Firstly, you can simply write
while True:
Instead of
a = True
while a:
Secondly, you don’t use total or t anywhere. You can delete them.
Thirdly, if x has to belong to [a, b], you can write
if a <= x <= b:
Fourthly, you can use else statement instead of negation of if. Also, when you have break in if statement, the code below won’t be executed if statement is true (it will break), so you even don’t have to use any else here.
The last part you can make by simple iteration in for loop and multiplying or adding strings (e.g. 5*’a’ = ‘aaaaa’)
while True:
width = int(input('Width (7-10): '))
if 7 <= width <= 10:
break
print('Invalid Number!')
while True:
border = int(input('Border (1-3): '))
if 1 <= border <= 3:
break
print('Invalid Number!')
for _ in range(border):
print(width*'*')
for _ in range (width - 2*border):
print(border*'*' + (width-2*border)*' ' + border*'*')
for _ in range(border):
print(width*'*')
solved for and while loop using break,pass,continue.I don’t know where I should go next [closed]