_Suraj_

test your Maths Skills

Jul 4th, 2024
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | Source Code | 0 0
  1. print(" ") # escape first line
  2.  
  3. # color text, underline text, bold text
  4. print("\033[33m\033[4m\033[1mπŸŽ‰Maths TestπŸŽ‰\033[m\n".center(70))
  5.  
  6. def math_test(): # function name
  7.  
  8.     print("\033[1m") # bold text
  9.    
  10.     # import random module
  11.     import random
  12.     symbol = ("+", "*", "/", "-")
  13.     opr = random.choice(symbol)
  14.     num1 = random.randint(1,50)
  15.     num2 = random.randrange(-50,100)
  16.    
  17.     # print maths equations
  18.     print (num2, opr, num1, " = ", end=" ")
  19.    
  20.     # take user answer
  21.     ans =float( input())
  22.    
  23.  # checking user answer
  24.     if opr == "+":
  25.         ans1 = num1 + num2
  26.         print(f"the addition of {num1} and {num2} is {ans1}πŸ’―. ")
  27.     elif opr =="*":
  28.         ans1 = num1 * num2
  29.         print(f"the multiplication of {num1} and {num2} is {ans1}πŸ’―. ")
  30.     elif opr =="/":
  31.         ans1 = num2 / num1
  32.         print(f"the divide of {num1} and {num2} is {ans1}πŸ’―. ")
  33.     elif opr =="-":
  34.         ans1 = num2 - num1
  35.         print(f"the subtraction of {num2} and {num1} is {ans1}πŸ’―. ")
  36.        
  37. # making decisions "true" or "false"
  38.     if ans == ans1:
  39.         print("You\'r answer is \"TRUE\"😎\n")                        
  40.     else:
  41.         print('You\'r answer is \"FALSE\"πŸ‘»\n')        
  42.  
  43. # "while" loop for create infinity equations
  44. while True:
  45.     math_test()    
  46.     a = input("write exit to quit. : ")
  47.     print(" ")
  48.     if a.lower() == "exit":
  49.         print("πŸ’₯run againπŸ’₯".center(70))
  50.         print("\033[m") # escape bold text
  51.         break
  52.        
  53. # Β©D.world        
Tags: python
Add Comment
Please, Sign In to add comment