Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I was wondering how to reset this program, and I need help. I have been looking everywhere for an answer, but I can't find a program that works. Can someone please help me?
print("Answer These MATH Questions")
def program():
math = int(input("What Is 8 x 4: "))
if math == ("32"):
print("You Got The Question Correct")
else:
print("Sorry You Got The Question Wrong Try Again")
program()
return
Use while like example. Don't use int for input - maybe it will not number:
while 1:
math = input("What Is 8 x 4: ")
if not math.isdigit():
print("It's not number")
elif math == "32":
print("You Got The Question Correct")
break
else:
print("Sorry You Got The Question Wrong Try Again")
change if math == ("32"): to if math == 32:
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Question is: Use procedure with parameter. Ask the user to input numbers until they say “no”. Output if each number is greater than or less than or equal to 5.
def output(number):
if number > 5:
print("Greater than 5")
elif number < 5:
print("Less than 5")
else:
print("It is equal to 5")
userInput = "yes"
print(userInput.lower() != "no")
num = input("Enter a number \n")
output(userInput)
userInput = input("Would you like to try again?")
You're trying to compare a str with an int. The following will fix it:
def output(number):
if number > 5:
print("Greater than 5")
elif number < 5:
print("Less than 5")
else:
print("It is equal to 5")
userInput = "yes"
print(userInput.lower() != "no")
num = int(input("Enter a number \n"))
output(userInput)
userInput = input("Would you like to try again?")
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to make a random number guessing game but I cant get the if statement to check if the users input is = to the random number
import random
realNumber = random.randint(1, 50)
print(realNumber)
myNumber = print(input("Guess the number from 1 to 50: "))
if int(myNumber) == realNumber:
print("You win")
else:
print("Nope guess again")
The unintended behavior of your program is due to this line:
myNumber = print(input("Guess the number from 1 to 50: "))
Here, you are trying to assign myNumber to the return value of the print statement (Which is None) and not the value obtained from the input() statement. To fix this, simply remove the print() around the input.
myNumber = input("Guess the number from 1 to 50: ")
Hope this helped!
You don't need the print statement around input.
import random
realNumber = random.randint(1, 50)
print(realNumber)
myNumber = input("Guess the number from 1 to 50: ")
if int(myNumber) == realNumber:
print("You win")
else:
print("Nope guess again")
Note that this code will not work if the user enters something besides an integer, because the int() call will not cast correctly
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have 2 questions about my code. Why the program doesn't go in the second if statement. How can I end the loop?
from random import *
SecretNumber=randint(1,5)
Guess=int(input("Please enter Guess: "))
NumberofGuesses=1
SecretNumber=0
while Guess != SecretNumber:
NumberofGuesses=NumberofGuesses+1
if Guess>SecretNumber:
print("Please insert a smaller number")
else:
print("Please insert a bigger number")
if Guess==SecretNumber:
print("Number of Guesses: {0}".format(NumberofGuesses))
Your second if is outside the while loop, so it won't get hit until you guesss the secret number. The loop never ends because you never read another guess.
You also have a problem that you are overriding your random secret number with zero.
You need something like:
import random
SecretNumber=random.randint(1,5)
NumberofGuesses=0
while true:
Guess=int(input("Please enter Guess: "))
NumberofGuesses += 1
if Guess == SecretNumber:
break # Got it!
elif Guess>SecretNumber:
print("Please insert a smaller number")
else:
print("Please insert a bigger number")
print("Number of Guesses: {0}".format(NumberofGuesses))
It's because you're setting SecretNumber to 0. Remove it and it should work.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
num = input(float("Enter a number (enter 'q' to quit): ")
p=0
while num>=1:
p=p+1
Why do I keep getting a syntax error on the first p?
Does this mean I can't assign a numerical value on a variable?
You should close the bracket
num = input(float("Enter a number (enter 'q' to quit): "))
import sys
num = input("Enter a number (enter 'q' to quit)")
try:
num = int(num)
except:
if num == 'q':
sys.exit()
p=0
while (num>=1):
p=p+1
num = num - 1 #otherwise it will go to infinite loop
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
import random
number= random.randint(1,10)
count=0
guess=""
guess=int(input("please guess:")
while guess!= number:
if guess < number:
print("lower")
count++
elif guess > number:
print("higher")
count++
elif guess==number:
print("Good job, you got my number")
print("You got it in,",count,"tries")
FOr some reason when i try to run it, it says I have invalid syntax. Please help.
This is Python, not C or JS. This:
count++
Should be written as:
count += 1
Also, your keep in mind that Python is indentation-sensitive.
while guess!= number:
if guess < number:
print("lower")
count++
elif guess > number:
print("higher")
count++
elif guess==number:
print("Good job, you got my number")
print("You got it in,",count,"tries")
And lastly, you're missing a closing parenthesis:
guess=int(input("please guess:"))
Well, good luck learning!
You're missing an end parenthesis
guess=int(input("please guess:")
Should be:
guess=int(input("please guess:"))
Hope that helps
You also need to change your indenting on this:
elif guess==number:
print("Good job, you got my number")
print("You got it in,",count,"tries")
Also do increment correctly