Please fix my number guessing game. If there is no errors, make it easier please! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please fix my number guessing game. If there is no errors, make it easier please!

Here is the code: import random numberguess = input(int()) numberandom = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'] number = random.choice(numberandom) print ("Pick a number 1 to 20!") if (numberguess == numberandom): print ("Nice! You guessed the right number! /n Correct Number:") print (number) else: print ("Incorrect. You sadly didn't guess the right number! \n Correct Number:") print ( number) print ("\n \n Guessed number: " + numberguess) numberandom2 = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] number2 = random.choice(numberandom2) print ("Easier Version:") print ("\nPick a number 1 to 10!") if (numberguess == numberandom2): print ("Nice! You guessed the right number! /n Correct Number:") print (number) else: print ("Incorrect. You sadly didn't guess the right number! \n Correct Number:") print ( number2) print ("\n \n Guessed number:" + numberguess)

19th Sep 2023, 8:35 PM
Bluegray
Bluegray - avatar
3 Answers
+ 5
For simplifying you can use random.randint and get rid of lists
19th Sep 2023, 9:13 PM
Mafdi
Mafdi - avatar
+ 3
Have you tried running your code? It's full of errors. Starting with input(int()) instead of int(input())), and ending with the fact that in the second case you don't even let the user enter the answer. You're comparing a number, to a string (in numberrandom). If you want a list of values, use range(1, n+1)
19th Sep 2023, 9:05 PM
Alexey Kopyshev
Alexey Kopyshev - avatar
+ 3
# Hi, Bluegray ! # You can take a look at this one: import random a, b = 1, 5 rand = random.randint(a, b) print (f"Pick a number {a} to {b}!") guess = int(input('>> ')) if guess == rand: print("\n\nNice! You guessed the right number!") else: print("\n\nIncorrect. You sadly didn't guess the right number!") print(f"\n\t-> Correct Number: {guess}")
19th Sep 2023, 9:23 PM
Per Bratthammar
Per Bratthammar - avatar