Jan-04-2019, 10:07 PM
Hello! This is my first ever post. I am really new to Python and programming in general. Only about a week that i try to figure out how to code.
I tried making a program that will generate a random number, then i input a number trying to guess the random one. The program tells me if my input is higher or lower than the number and i guess again until i find the correct one. Finally it notifies me that i found the correct number and also how many attempts i needed to find it.
While i m pretty sure my logic behind this is correct, i run into silly syntax errors that probably come from the "if" statement. I am using Python 3.7
I ve seen that the syntax should be
if condition:
commands
elif condition:
commands
else:
commands
while it seems simple it wont work :)
my code is the following
also if i try to put the : in the first if statement i get this https://i.imgur.com/c7avGC0.png
I am trying to solve this for 3h now ruining my study and i finally decided that i need help for someone with experience!
Thank you in advance!
I tried making a program that will generate a random number, then i input a number trying to guess the random one. The program tells me if my input is higher or lower than the number and i guess again until i find the correct one. Finally it notifies me that i found the correct number and also how many attempts i needed to find it.
While i m pretty sure my logic behind this is correct, i run into silly syntax errors that probably come from the "if" statement. I am using Python 3.7
I ve seen that the syntax should be
if condition:
commands
elif condition:
commands
else:
commands
while it seems simple it wont work :)
my code is the following
import random z = int(random.randint(0,100)) att = int(0) # att will be used to count the attemps inside my loop solve = False # I use solve as an exit mechanic from while loop while solve == False: x = input(int('Enter your guess: ') if x > z print('The number is smaller than the input') guess = att + 1 elif x < z: print('The number is bigger than the input') guess = att + 1 else: print('Congratulations! You have found the correct number!') print('It took you ' + int(guess) + 'attemps') solve = TrueThe error i get is this https://i.imgur.com/5PFCcNW.png
also if i try to put the : in the first if statement i get this https://i.imgur.com/c7avGC0.png
I am trying to solve this for 3h now ruining my study and i finally decided that i need help for someone with experience!
Thank you in advance!