Advertisement
DrAungWinHtut

exam.py

Jan 3rd, 2023
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. import random
  2. import os
  3.  
  4. marks = 0
  5.  
  6.  
  7. def funAdd():
  8.     global marks
  9.     print('#### This is Adding Game ####')
  10.  
  11.     for i in range(0, 1):
  12.         a = random.randint(0, 100)
  13.         b = random.randint(0, 100)
  14.         sum = a + b
  15.         print('please add a = ', a, ' and b = ', b)
  16.         ans = eval(input('your ans: '))
  17.         f.writelines(str(a) + '+'+str(b) + '='+str(sum)+'%')
  18.         f.writelines(str(ans)+'%')
  19.         if ans == sum:
  20.             marks = marks + 1
  21.             print('Right answer! Total marks is now ', marks)
  22.             f.writelines('1%')
  23.         else:
  24.             print('Wrong answer!Total marks is now ', marks)
  25.             f.writelines('0%')
  26.         input()
  27.         f.writelines('\n')
  28.         os.system("cls")
  29.  
  30.  
  31. def funMul():
  32.     global marks
  33.     print('#### This is Multiplying Game ####')
  34.  
  35.     for i in range(0, 1):
  36.         a = random.randint(0, 100)
  37.         b = random.randint(0, 100)
  38.         mul = a * b
  39.         print(a, ' * ', b, ' = ')
  40.         ans = eval(input())
  41.         f.writelines(str(a) + '*'+str(b) + '='+str(mul)+'%')
  42.         f.writelines(str(ans)+'%')
  43.  
  44.         if ans == mul:
  45.             marks = marks + 1
  46.             print('Right answer! Total marks is now ', marks)
  47.             f.writelines('1%')
  48.         else:
  49.             print('Wrong answer!Total marks is now ', marks)
  50.             f.writelines('0%')
  51.  
  52.         input()
  53.         f.writelines('\n')
  54.         os.system("cls")
  55.  
  56.  
  57. print('#### This is Math Game ####')
  58. name = input('What is your name: ')
  59. student_id = input('What is your student ID: ')
  60. file_name = name+student_id+".dat"
  61. global f
  62. f = open(file_name, 'at')
  63.  
  64. while 1:
  65.     print('1-Adding Game')
  66.     print('2-Multiplying Game')
  67.     print('3-Exit')
  68.     choice = input('Please choose 1 or 2: ')
  69.     if choice == '1':
  70.         funAdd()
  71.     elif choice == '2':
  72.         funMul()
  73.     elif choice == '3':
  74.         f.close()
  75.         quit()
  76.     os.system('cls')
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement