Login

Back

Generating numbers - Answers

Q1. Type the code in and get it working.
Q2 E.g.

\newline Backslash and newline ignored
\\ Backslash (\)
\' Single quote (')
\" Double quote (")
\a ASCII Bell (BEL)
\b ASCII Backspace (BS)
\f ASCII Formfeed (FF)
\n ASCII Linefeed (LF)
\r ASCII Carriage Return (CR)
\t ASCII Horizontal Tab (TAB)
\v ASCII Vertical Tab (VT)
\ooo Character with octal value ooo (1,3)
\xhh Character with hex value hh

Q3a.

print("Let's generate some numbers.")
print('It will be fun ...')

print("\n\nCounting ...")
for i in range(1, 21):
      print (i,end=" ")

Q3b. 

print("Let's generate some numbers.")
print('It will be fun ...')

print("\n\nCounting ...")
for i in range(1, 21):
     print (i,end="\t")

Q4.  

print("12 times table")
for i in range(1,13):
     print(i,"times 12 is",i*12)

Q5.

print("12 times table in reverse")
for i in range(12,0,-1):
     print(i,"times 12 is",i*12)

Q6.

yourNumber = int(input("What number shall I use? >>> "))

print("\n\nA times table ...")
for i in range(1,12):
     print(i, "*", yourNumber,"=",i*yourNumber)

Q7. If you don't use int, you will be multiplying string values. You will produce a pattern of numbers. (Remove the int instruction and see.)

Q8.

yourNumber = int(input("What number shall I use? >>> "))

print("\n\nA times table ...")
for i in range(1,120):
     print(i, "*", yourNumber,"=",i*yourNumber)

Q9.

yourNumber = int(input("What number shall I use? >>> "))

print("\n\nA times table ...")
for i in range(120,0,-1):
     print(i, "*", yourNumber,"=",i*yourNumber)

Q10.

yourNumber = float(input("What decimal shall I use? >>> "))
print("\n\nA timestable ...")
for i in range(1,12):
     print(i, "*", yourNumber2,"=",i*yourNumber2,2)

Back