+ 1
Guys can anybody pin point what is wrong?
When I enter a value in p1 like 10 or 1000 and a value of 9 in p2 I always get that p2 in bigger than p1! https://code.sololearn.com/ciqFE5g3F5zM/?ref=app
4 ответов
+ 3
You're very much correct Maz on needing to change lines 1-2 (surround both inputs with an int() function), no worries. Otherwise it simply compares the strings, not the value itself. ^^
The individual character comparison is done on the Unicode level from what I understand.
Here's your code again Author, I also added proper indentation.
p1 = int(input())
p2 = int(input())
if p1 > p2:
print("player 1 won the game")
else:
if p2 > p1:
print("player 2 won the game")
x = input("do you want a rematch? ")
print(x)
if x == "yes":
print("game will start shortly.")
if x == "no":
print("game over, see you next time. ")
+ 12
I do not know how Python considers strings comparison, but you did not convert your input in numbers and Python manage them as normal strings (probably making a comparison with their ASCII values)
Replace your first two lines with:
p1=int(input())
p2=int(input())
... or this other one to manage float numbers:
p1=float(input())
p2=float(input())
+ 1
Thnx saphire :)
0
Thanks alot, that was a big help.