Mar-15-2020, 04:42 PM
Hello, I am new to Python and was trying this code (which is used to guess the number picked by system -using the random function-) and I wanted to add some features, such as:
If the number picked by user is higher than the one picked by the random function, print "the number you picked is lower", and the same thing if it's lower (print: "it's higher").
* To be clear: I want to save (a variable) the input throught "stdin"(of type int - I know I have to cast it from str to int-), and then use this variable to keep referencing the user input to improve my code and do what I explained on the 2nd paragraph.
This is the orignal code (working ok, but with no features):
If the number picked by user is higher than the one picked by the random function, print "the number you picked is lower", and the same thing if it's lower (print: "it's higher").
* To be clear: I want to save (a variable) the input throught "stdin"(of type int - I know I have to cast it from str to int-), and then use this variable to keep referencing the user input to improve my code and do what I explained on the 2nd paragraph.
This is the orignal code (working ok, but with no features):
import random secret = random.randint(0,50) message = 'Pick a number from 1 to 49: ' even_number = (secret % 2) == 0 if even: print("The number is even") else: print("The number is odd") attempts = 0 MAX = 5 while int(input(message)) != secret: if attempts >= MAX -1: print("You loose") break else: attempts += 1 print('No!') else: print('You guessed!')Thank you in advance!!