I need help with this code! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need help with this code!

I need help with this code: #This is my 2nd game in Python #Importing the nesary module import random #Creating the variables words = ["Python","C++","Java","JavaScript","C#","PHP","Swift","C","Ruby","jQuery","HTML","CSS","SQL"] word = random.choice(words) tries = 1 guess = -1 #Main code goes here while guess != tries: guess = int(input()) if guess == word: print("Congrats, you won!If you like it an upvote will be apreciated!") else: print("Bad luck.Try again!") tries -= 1 It says: Traceback (most recent call last): File "./Playground/file0.py", line 14, in <module> guess = int(input("")) ValueError: invalid literal for int() with base 10: 'Swift' Where Swift is what i put at the input

25th Jan 2020, 9:29 PM
xAlexMinecraft
xAlexMinecraft - avatar
8 Answers
+ 2
Not... guess = int(input()) use.... guess = input() also while tries > 0
25th Jan 2020, 9:59 PM
rodwynnejones
rodwynnejones - avatar
+ 6
Okay sure, but where is line 14 ? Rewrite this in code playground, and share the link here please. It would also be more helpful if you provide more info about what you want to do, and the purpose of your code.
25th Jan 2020, 9:41 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
xAlexMinecraft so I guess it works now ?
25th Jan 2020, 11:55 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Guess takes integer as input. Rewrite the first line inside while loop to take string as input.
25th Jan 2020, 9:54 PM
Khatakh
Khatakh - avatar
+ 1
Aymane Boukrouh yes it work now!Go to play it and if you like it give an upvote!
26th Jan 2020, 8:35 AM
xAlexMinecraft
xAlexMinecraft - avatar
+ 1
Btw is very hard!Good luck!
26th Jan 2020, 8:42 AM
xAlexMinecraft
xAlexMinecraft - avatar
+ 1
Remove int() from int(input())
26th Jan 2020, 9:13 PM
Younes Abdulnabi
Younes Abdulnabi - avatar
0
Thanks! I want to do a word guesing game with programming languages! The only thing that was is to change guess = int(input()) to guess = input(), and while guess =! tries to while tries > 0. Also this is a link to my game: https://code.sololearn.com/c91dA4Hms5mQ/#py
25th Jan 2020, 10:13 PM
xAlexMinecraft
xAlexMinecraft - avatar