[Tutor] A Question about coding style

Manprit Singh manpritsinghece at gmail.com
Thu Sep 16 21:35:44 EDT 2021


Dear sir,

If I have to write a program, that allows the user to input a number and
assign it to a variable b, if the number entered is a negative number,
assign 0 to variable b.
At last print the value of variable b. The code that i have written is
given below:

b = int(input("Enter a  number"))
if b < 0: b = 0
print(b)

See the whole if statement part is written in single line, is it acceptable
?

Second example is of a for loop, which is also written in single line
for i in range(6): print(i)   # print values from 0 to 5,is it also
acceptable ?

Kindly guide
Regards
Manprit Singh


More information about the Tutor mailing list