+ 2

How to fix the bug in Python code

text1 = input("hello: ") text2 = input("nasa: ") text3 = input("bmw: ") # convert to uppercase text1_uppercase = text1.upper() text2_uppercase = text2.upper() text3_uppercase = text3.upper() # display on the screen print(text1_uppercase) print(text2_uppercase) print(text3_uppercase) # Get user input text1 = input("hello: ") text2 = input("nasa: ") text3 = input("bmw: ") # Check if user input is NASA if text2.upper() != "NASA": print("Please enter NASA when asked for a company.") else: # Convert to uppercase text1_uppercase = text1.upper() text2_uppercase = text2.upper() text3_uppercase = text3.upper() # Display on the screen print(text1_uppercase) print(text2_uppercase) print(text3_uppercase)

17th Dec 2023, 4:55 AM
BEHCET AYTIMUR AHISKA
BEHCET AYTIMUR AHISKA - avatar
9 Answers
+ 2
Hey, You code looks good to me, but there's a small mistake in the conditional check. You should compare text2_uppercase instead of text2.upper() in the condition. Here's the corrected version: # Get user input text1 = input("hello: ") text2 = input("nasa: ") text3 = input("bmw: ") # Check if user input is NASA if text2.upper() != "NASA": print("Please enter NASA when asked for a company.") else: # Convert to uppercase text1_uppercase = text1.upper() text2_uppercase = text2.upper() text3_uppercase = text3.upper() # Display on the screen print(text1_uppercase) print(text2_uppercase) print(text3_uppercase)
17th Dec 2023, 5:18 AM
ć‚ă„šă„©äž‚ć„
ć‚ă„šă„©äž‚ć„ - avatar
+ 2
What bug you are facing in code? Can you mention details clearly...
17th Dec 2023, 5:37 AM
Jayakrishna 🇼🇳
+ 2
Aside the code playground is not interactive, there is a confusion in your code. At the very beginning, with a code like this >>text1 = input("hello: ")<<, the screen will print >>hello: << and wait for the user input. Unless the message means to tell the user enter "hello" and without the colon, the message printed on screen is confusing. A better way is input("Please enter 'hello' and press ENTER: ") to eliminate any confusion. The following code doesn't work very well in the playground. if text2.upper() != "NASA": print("Please enter NASA when asked for a company.") Due to playground is not interactive, you have to think ahead how the code runs. With your code you need to input something like this in the input prompt box. hello nasa bmw abc xyz 123 With all 6 inputs provided your code will run in the playground. Since the 5th input is not NASA, it will print "Please enter NASA when asked for a company." and the program exit. If 5th input is NASA, it will return all the input in uppercase.
17th Dec 2023, 10:40 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
BEHCET AYTIMUR AHISKA , You can't do that kind of interactivity on Sololearn in the Code Playground, because the playground requires the user to submit all inputs before running the program, which it stores. It then supplies them to the program one by one while it is running. Technically, if you know all your branches, you could still use it to test by preloading the inputs that would take you to those branches if the program were running, but it's a hassle.
17th Dec 2023, 6:52 AM
Rain
Rain - avatar
+ 1
BEHCET AYTIMUR AHISKA , By the way, since input returns a string, you can use the .upper() method on it immediately and avoid creating extra variables. text1 = input("hello: ").upper()
17th Dec 2023, 7:10 AM
Rain
Rain - avatar
0
Whatever you write to fix the bug does not work out. Something other than you mentioned does not run properly. I am really fed up, anyway.
17th Dec 2023, 7:33 AM
BEHCET AYTIMUR AHISKA
BEHCET AYTIMUR AHISKA - avatar
0
from turtle import * speed(10) color('cyan') bgcolor('black') b = 200 while b > 0: left(b) forward(b * 3 b = b - 1 Please help me code is not working properly
18th Dec 2023, 2:45 PM
Santosh Choudhary
Santosh Choudhary - avatar
0
Santosh Choudhary , You should start a new discussion, but you're missing a closing ).
18th Dec 2023, 3:49 PM
Rain
Rain - avatar