Today I was very bored, and I decided to do programming! I’m going to make a multiplication table!
What I’m going to to:
- Do input and int assigned to a variable
- Use while loop
- Use for loop
- Make it pretty
Step 1:
First I’m going to make a variable called “num” and them use input to ask the person a question to grab info from. And I’m salso going to use “int” to make the string a integer.
Like this:
num = input("Give me a number between 1 and 12: ")
Now to step 2.
Step 2:
Next, I’m going to use while loops! Like this:
while 1 > num or num > 12:
num = int(input("Please enter a number between 1 and 12: "))
Step 3:
For loops. So that I can print the multiplication table.
for item in range(1, 13):
print(f" {num} x {item:2d} = {num*item:3d} ")
MAKE IT PRETTY!
print("----------------------------------------------------")
for item in range(1, 13):
print(f" {num} x {item:2d} = {num*item:3d} ")
print("----------------------------------------------------")
Final:
Input:
num = int(input("Give me a number between 1 and 12: "))
while 1 > num or num > 12:
num = int(input("Please enter a number between 1 and 12: "))
print("----------------------------------------------------")
for item in range(1, 13):
print(f" {num} x {item:2d} = {num*item:3d} ")
print("----------------------------------------------------")
Output:
num = int(input("Give me a number between 1 and 12: "))
while 1 > num or num > 12:
num = int(input("Please enter a number between 1 and 12: "))
print("----------------------------------------------------")
for item in range(1, 13):
print(f" {num} x {item:2d} = {num*item:3d} ")
print("----------------------------------------------------")
Notice: Example if I put 3
I’m pretty sure you didn’t learn that much from this. Maybe the next one I do, I’ll explain thoroughly.
Bye!