I'm trying to make a warmer / colder game in python as a project. Currently, when I open the program it closes immediately despite there being several loops and inputs. I have spent a good 2 hours on it, and I can't figure it out. Any tips?
import random
Correct = random.randint(1, 100)
Oldval = 50
Newval = 50
while Newval != Correct:
Newval = Newval + input("How much do you want to move?")
if (Newval - Correct) > (Oldval - Correct):
print("Colder!")
else:
print("Warmer!")
Oldval = Newval
Win = input(You Win!)
You were trying to add a string and an integer. Also, your final input didn't have quotes around the You Win!
string. Here's the code with the issues fixed:
import random
correct = random.randint(1, 100)
oldval = 50
newval = 50
while newval != correct:
newval = newval + int(input("how much do you want to move?"))
if (newval - correct) > (oldval - correct):
print("Colder!")
else:
print("Warmer!")
oldval = newval
win = input("You Win!")
You could use pylint
tool to detect the error like missing quotes. pylink test.py
E: 12, 0: invalid syntax (<string>, line 12) (syntax-error)
You could install pylint
using pip install pylint
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.