CodingNoob CodingNoob - 5 years ago 74
Python Question

Why doesn't this print the times tables?

Number=int(input('Give me a number :'))
count=1
print(str(count)+'*'+str(Number)+'='+str(count*Number))
while count<10 :
count=count+1


How do I display a chosen timetable by using condition controlled loops ?

Answer Source

Firstly, you need to indent the counting statement.

Number=int(input('Give me a number :'))
count=1
print(str(count)+'*'+str(Number)+'='+str(count*Number))
while count<10 :
    count=count+1

Further, in order to display your results, you must move line 3 into your loop. The second and last example I gave you are both fully operational, however the last one is certainly more effective.

Number=int(input('Give me a number :'))
count=1
while count<10 :
    print(str(count)+'*'+str(Number)+'='+str(count*Number))
    count=count+1

Also, some programming tips. If you want to increase the value of count you could simply type:

count+=1

But Certainly the best approach would be to use a for loop. Like so,

Number=int(input('Give me a number :'))
for i in range(10) :
    print(str(i)+'*'+str(Number)+'='+str(i*Number))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download