Is there any wrong thing in this code?. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is there any wrong thing in this code?.

if usr in value: print ("Nice work, you guessed right") else: print ("Better luck next time") print ("Hope you like it, ")

19th May 2017, 9:52 PM
Dylee
Dylee - avatar
13 Answers
+ 1
the input() function returns the value the user enters as a string. here are some changes you can make: https://code.sololearn.com/cInhj9Ck6zv7/?ref=app
19th May 2017, 10:24 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
Thanks
19th May 2017, 10:28 PM
Dylee
Dylee - avatar
+ 2
A lot
19th May 2017, 10:29 PM
Dylee
Dylee - avatar
+ 1
but I get a TypeError code
19th May 2017, 10:11 PM
Dylee
Dylee - avatar
+ 1
should I paste the full code?
19th May 2017, 10:11 PM
Dylee
Dylee - avatar
+ 1
import math from math import * import random print (".....") usr = input("Enter a Number") for i in range(5): value = random.randint(1, 6) print(value) if usr in value: print (".....t") else: print (".....") print ("....")
19th May 2017, 10:17 PM
Dylee
Dylee - avatar
+ 1
value is a list and usr is an int
19th May 2017, 10:18 PM
Dylee
Dylee - avatar
+ 1
value is like a list of ints
19th May 2017, 10:19 PM
Dylee
Dylee - avatar
+ 1
but i didn't use usr as "str" so how is that possible and please show me what I can do to solve this
19th May 2017, 10:22 PM
Dylee
Dylee - avatar
0
if usr and value are variables then I see no problem.
19th May 2017, 10:10 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
if you post a link for the code in the playground is even better.
19th May 2017, 10:15 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
what type is usr and value?
19th May 2017, 10:18 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
But according to your code value is of type int and usr is of type string. That's why your getting the TypeError.
19th May 2017, 10:20 PM
Ulisses Cruz
Ulisses Cruz - avatar