+ 1
What's the problem with line 5 of my code?
import random a = random.randint (0,9) print ("Your suitcase is locked with a 4-digit lock. It wouldn't be a problem if you hadn't forgot the combination. So, you have to guess the numbers one by one. From 0 to 9.") b = int(input("Guess the first number:") if b == a: print ("You did it. The number is " + b) elif b > a: print ("The number is smaller.") else: print ("The number is bigger") The code is in Python.
8 Antworten
+ 6
A closing parentheses was missing at the line where you read value for variable <b>
b = int(input("Guess the first number")) # <-- this line
+ 7
The elif and else are indented one level too many – They need to be matched with the if
+ 5
You cannot add a string and an integer.
You should first convert your integer to a string:
print(“You did it. The number is “ + str(b))
+ 1
You're right. That was the problem. Thnx.
Now I have to write the rest of the code.
+ 1
In if b == a's print statenent you should use str(b) to avoid TypeError (cannot concatenate integer to string)
0
I tried. Nothing happened. It always points to the colon on the end of line 5
if b === a:
0
Bug
0
On line 5, there is a missing closing parenthesis.
Correct code: b = int(input("Guess the first number."))