Print the result of the operations on Python
Question:
I need to print the result of each Num to make a face. By putting three pairs of numbers, each one will give you a symbol, and in the end I need to print together all the symbols received before.
Num1 = int(input("Tell me a whole number: "))
if Num1 % 6 == 0:
print (":")
elif Num1 % 2 == 0:
print("X")
elif Num1 % 3 == 0:
print("8")
elif Num1 % 4 == 0:
print ("=")
elif Num1 % 5 == 0:
print("[")
elif Num1 % 1== 0:
print(";")
Num2 = int(input("Tell me a whole number: "))
if Num2 % 4 == 0:
print ("-")
elif Num2 % 2 == 0:
print("-{")
elif Num2 % 3 == 0:
print("<{")
elif Num2 % 1== 0:
print("<")
Num3 = int(input("Tell me a whole number: "))
if Num3 % 7 == 0:
print ('(')
elif Num3 % 2 == 0:
print("O")
elif Num3 % 3 == 0:
print("|")
elif Num3 % 4== 0:
print("!")
elif Num3 % 5 == 0:
print("/")
elif Num3 % 6 == 0:
print("P")
elif Num3 % 1== 0:
print(")")
I tried this, but it will only print the numbers that were input before, and not the symbols. What can I do?
print(Num1, Num2, Num3)
Answers:
print
as the name suggests prints something onto the console.
As you want to create a face, you should instead of print
store the face parts in a variable.
Going by your code here is a shorter example:
face = ""
num = int(input("Tell me a whole number: "))
# IF num is divisible by 6
if num % 6 == 0:
# THEN concatenate ":" at the end of the string
face += ":"
# ELSE IF num is divisible by 2
elif num % 2 == 0:
# THEN concatenate "X" at the end of the string
face += "X"
# GET next number
num = int(input("Tell me a whole number: "))
# Concatenate next string part to face
if num % 4 == 0:
face += "-"
elif num % 2 == 0:
face += "-{"
# Get last number
num = int(input("Tell me a whole number: "))
if num % 7 == 0:
face += '('
elif num % 2 == 0:
face += "O"
print(face)
This will give you the following output when entering the numbers 6
, 4
and 7
:
:-(
I need to print the result of each Num to make a face. By putting three pairs of numbers, each one will give you a symbol, and in the end I need to print together all the symbols received before.
Num1 = int(input("Tell me a whole number: "))
if Num1 % 6 == 0:
print (":")
elif Num1 % 2 == 0:
print("X")
elif Num1 % 3 == 0:
print("8")
elif Num1 % 4 == 0:
print ("=")
elif Num1 % 5 == 0:
print("[")
elif Num1 % 1== 0:
print(";")
Num2 = int(input("Tell me a whole number: "))
if Num2 % 4 == 0:
print ("-")
elif Num2 % 2 == 0:
print("-{")
elif Num2 % 3 == 0:
print("<{")
elif Num2 % 1== 0:
print("<")
Num3 = int(input("Tell me a whole number: "))
if Num3 % 7 == 0:
print ('(')
elif Num3 % 2 == 0:
print("O")
elif Num3 % 3 == 0:
print("|")
elif Num3 % 4== 0:
print("!")
elif Num3 % 5 == 0:
print("/")
elif Num3 % 6 == 0:
print("P")
elif Num3 % 1== 0:
print(")")
I tried this, but it will only print the numbers that were input before, and not the symbols. What can I do?
print(Num1, Num2, Num3)
print
as the name suggests prints something onto the console.
As you want to create a face, you should instead of print
store the face parts in a variable.
Going by your code here is a shorter example:
face = ""
num = int(input("Tell me a whole number: "))
# IF num is divisible by 6
if num % 6 == 0:
# THEN concatenate ":" at the end of the string
face += ":"
# ELSE IF num is divisible by 2
elif num % 2 == 0:
# THEN concatenate "X" at the end of the string
face += "X"
# GET next number
num = int(input("Tell me a whole number: "))
# Concatenate next string part to face
if num % 4 == 0:
face += "-"
elif num % 2 == 0:
face += "-{"
# Get last number
num = int(input("Tell me a whole number: "))
if num % 7 == 0:
face += '('
elif num % 2 == 0:
face += "O"
print(face)
This will give you the following output when entering the numbers 6
, 4
and 7
:
:-(