+ 3
Ptyhon delvopment fasten your seatbelt
I donât see whatâs wrong with the code I put fasten my seatbelt three times I donât see whatâs wrong Here is my code fasten your seatbelt fasten your seatbelt fasten your seatbelt
5 Answers
+ 4
Yes
+ 4
There are few mistakes I found.
1. The required output is "Fasten your seat belt" and print it 3 times. Not "fasten your seatbelt". Case and space have to match exactly.
2. Where is the print()?
3. The most important one. This practice is about for loop. Your solution with correct syntax can pass the test though, it is not intended to be solving like this.
How would you do if the practice asks you to print it 1000 times? Would you copy the same instruction 1000 times?
Follow the comments given in the exercise and try the for loop approach.
+ 1
Hehe
+ 1
Oh i see
0
Christian Francis, without the print() function there's no use of this code. Nothing will be displayed on the screen.
It is best to use a for loop for executing programs like this. But, if you're a beginner and wish to avoid loop statements, here's another way to do this:
print('fasten your seatbelt\n' *3)
Output:
fasten your seatbelt
fasten your seatbelt
fasten your seatbelt
Explanation:
String multiplication has been used here. The original string gets repeated three times for *3 (i.e. n times for *n).
[Note:- Make sure you do not multiply with 0 or a negative integer because that will return an empty string (no output) and a float will raise a TypeError. ]
When you use the newline character (\n) in a string, it tells the python interpreter to break and start from a new line. So, each repeation appears on a new line.