This is an assignment for a computer science class. Is there a way to make it work, or do this more efficiently? The goal of the program is to have the user guess all four numbers (doesn't have to be in order), tell them if they are correct and display the amount of tries. The assignment requires at least one function with parameters and one list be included.
import random
# Sets tries and isCorrect to 0- not broken
tries = 0
isCorrect = 0
# Generates 4 random numbers- not broken
for i in range(4):
code = random.randint(1, 9)
code1 = random.randint(1, 9)
code2 = random.randint(1, 9)
code3 = random.randint(1, 9)
# Prints the random numbers for now- not broken
print(code)
print(code1)
print(code2)
print(code3)
# Guess = If the guess variables are equal to the code it tells you you're right
def guess(a, b, c, d):
global isCorrect
if a == code or code1 or code2 or code3 and b == code or code1 or code2 or code3 and c == code or code1 or code2 or code3 and d == code or code1 or code2 or code3:
print("You got it correct!")
else:
print("You got it wrong.")
return(a, b, c, d)
# While isCorrect is still 0 it prompts you to guess again, if it's correct it sets isCorrect to one
while isCorrect == 0:
gcode = int(input("Input your first guess: "))
gcode1 = int(input("Input your second guess: "))
gcode2 = int(input("Input your third guess: "))
gcode3 = int(input("Input your fourth guess: "))
guess(gcode, gcode1, gcode2, gcode3)
tries = tries + 1
#print("You got it wrong.")
if gcode == code or code1 or code2 or code3 and gcode1 == code or code1 or code2 or code3 and gcode2 == code or code1 or code2 or code3 and gcode3 == code or code1 or code2 or code3:
isCorrect = 1
# Makes it so the plural matches amount of tries
if tries != 1:
print("It took you", tries, "tries.")
else:
print("It took you", tries, "try.")