JoshBarkus / Josh

0 stars 0 forks source link

I need to put some code into pseudocode. #1

Open JoshBarkus opened 7 years ago

JoshBarkus commented 7 years ago

print("welcome to Bulls and Cows.") print("This is a game where you must guess the random number created by the computer. It will tell you how many Cows and how many Bulls you have at the end of each guess.") print("Good Luck!")

Bulls and Cows is set to 0

Bulls = 0 Cows = 0

genNum is set to a list. Each one is set to -1 so they aren't in the list already

genNum =[-1,-1,-1,-1]

userInput is set to a list. Each one is set to -1 so they aren't in ther list already

userInput = [-1,-1,-1,-1]

The randomly generated number is created with four numbers

import random

Imports random library

genNum[0] = random.randint (0,9) genNum[1] = random.randint (0,9) genNum[2] = random.randint (0,9) genNum[3] = random.randint (0,9)

The while loop is if one randomly generated number equals another, it creates another random four digit numebr until there are no duplicates

while genNum[0] == genNum[1] or genNum[0]== genNum[2] or genNum[0] == genNum[3] or genNum[1] == genNum[2] or genNum[1] == genNum[2] or genNum[1] == genNum[3] or genNum[2] == genNum[3]: genNum[0] = random.randint (0,9) genNum[1] = random.randint (0,9) genNum[2] = random.randint (0,9) genNum[3] = random.randint (0,9)

The while loop checks each individul random number with the numbers entered by the user. Asks user to enter 4 numbers, one at a time

userInput[0] = input("Enter the first number") userInput[1] = input("Enter the second number") userInput[2] = input("Enter the third number") userInput[3] = input("Enter the fourth number")

If checks if the numbers enter are valid, if they're invalid it asks the user to enter 4 numbers again

while userInput[0].isdigit() == False or userInput[1].isdigit() == False or userInput[2].isdigit() == False or userInput[3].isdigit() == False or userInput[0] == userInput[1] or userInput[0] == userInput[2] or userInput[0] == userInput[3] or userInput[1] == userInput[2] or userInput[1] == userInput[3] or userInput[2] == userInput[3] or len (userInput[0]) != 1 or len (userInput[1]) != 1 or len (userInput[2]) != 1 or len (userInput[3]) != 1:

Asks the user to enter four different numbers

print("You must enter four different numbers") userInput[0] = input("Enter the first number") userInput[1] = input("Enter the second number") userInput[2] = input("Enter the third number") userInput[3] = input("Enter the fourth number")

End If

If any random numbers are equal to the user input in the same place, it adds 1 to Bulls, if they're in different places to the list, it adds 1 to Cows. It then prints Bulls and Cows

if genNum[0] == int(userInput[0]): Bulls = Bulls + 1 elif int(userInput[0]) in genNum: Cows = Cows + 1 if genNum[1] == int(userInput[1]): Bulls = Bulls + 1 elif int(userInput[1]) in genNum: Cows = Cows + 1 if genNum[2] == int(userInput[2]): Bulls = Bulls + 1 elif int(userInput[2]) in genNum: Cows = Cows + 1 if genNum[3] == int(userInput[3]): Bulls = Bulls + 1 elif int(userInput[3]) in genNum: Cows = Cows + 1

Prints Buls and Cows

print("You have", Bulls, "bulls and",Cows,"cows")

JoshBarkus commented 7 years ago

I need it soon if possible