+ 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.

11th Jun 2022, 10:10 PM
Hisham H
Hisham H - avatar
8 odpowiedzi
+ 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
11th Jun 2022, 11:08 PM
Ipang
+ 7
The elif and else are indented one level too many – They need to be matched with the if
11th Jun 2022, 10:35 PM
Lisa
Lisa - avatar
+ 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))
11th Jun 2022, 10:55 PM
Alvaro GV
+ 1
You're right. That was the problem. Thnx. Now I have to write the rest of the code.
11th Jun 2022, 11:12 PM
Hisham H
Hisham H - avatar
+ 1
In if b == a's print statenent you should use str(b) to avoid TypeError (cannot concatenate integer to string)
13th Jun 2022, 3:31 PM
Stefan Corneteanu
Stefan Corneteanu - avatar
0
I tried. Nothing happened. It always points to the colon on the end of line 5 if b === a:
11th Jun 2022, 10:46 PM
Hisham H
Hisham H - avatar
0
Bug
13th Jun 2022, 4:45 AM
D. Mard
D. Mard - avatar
0
On line 5, there is a missing closing parenthesis. Correct code: b = int(input("Guess the first number."))
13th Jun 2022, 5:20 PM
MyNameIsNotBob
MyNameIsNotBob - avatar