حالت آفلاین — محتوا از حافظهٔ کش نمایش داده می‌شود
همهٔ تمرین‌ها

آزمون ریاضی

تمرین آسان 2837 visibility link download flag

برنامه ای بنویسید که بصورت تصادفی سوالات مختلف ریاضی چاپ کند و سپس جواب کاربر را دریافت و بررسی کند


مثال:

2 + 3 = ?
input: 5
** doroste **

55 * 2 = ?
input: 111
** eshtebahe **

...


در نهایت مجموع امتیاز کاربر را نمایش دهید (هر جواب درست 3 امتیاز مثبت و هر جواب اشتباه 1 امتیاز منفی)

این تمرین یه پروژه ست! یعنی پتانسیل اینو داره که خیلی بیشتر روش کار بشه بنابراین ایده اصلی رو از اینجا بردار و خودت بیشتر روش کار کن تا به یه تمرین بزرگتر تبدیل یشه
👨‍💻 2 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

پاسخ‌ها 17

import random

score = 0

for i in range(10):
    a = random.randint(1, 20)
    b = random.randint(1, 20)
    op = random.choice(["+", "-", "*"])

    if op == "+":
        answer = a + b
    elif op == "-":
        answer = a - b
    else:
        answer = a * b

    print(f"{a} {op} {b} = ?")
    user_answer = int(input("input: "))

    if user_answer == answer:
        print("** doroste **")
        score += 3
    else:
        print("** eshtebahe **")
        score -= 1

print(f"Score: {score}")
import random

def generate_question():
    operations = ['+', '-', '*', '/']
    num1 = random.randint(1, 10)
    num2 = random.randint(1, 10)
    operation = random.choice(operations)
    if operation == '+':
        answer = num1 + num2
    elif operation == '-':
        answer = num1 - num2
    elif operation == '*':
        answer = num1 * num2
    elif operation == '/':
        answer = num1 / num2
    return f"{num1} {operation} {num2} = ?", answer

score = 0

for _ in range(5):  # Ask 5 questions
    question, correct_answer = generate_question()
    user_input = float(input(question))

    if user_input == correct_answer:
        print("** doroste **")
        score += 3
    else:
        print("** eshtebahe **")
        score -= 1

print(f"Total score: {score}")
پاسخ هوش مصنوعی Ai Python
from random import randint
import random 
level = 0
count = 0
while True:
    p=(randint(1,10))
    print ('p= ',p)
    f=(randint(1,10))
    print ('f= ',f)
    g= (random.choice ('+×÷^-'))
    print ('quiz: ',p,g,f ,'= ')
    if g == '+':
        ans = p+ f
    elif g == '-':
        ans = p - f
    elif g=='×':
        ans=p * f
    elif g=='÷':
        ans=p / f
    elif g=='^':
        ans= p ** f
    print ('ans=',ans)
    try:
        user_ans =float(input ('inter your answer: '))
        if ans == user_ans:
            print ('good')
            level += 1
            count += 1
        elif ans != user_ans:
            print ('wrong')
            #level -= 1
            count += 1
    except :
        print ('plz inter intiger!')
        exit= input('do you want to exit? y/n\n'.lower())
        #exit = lower.exit()
        if exit =='y':
            break
        else:
            continue 
            #user_ans =(input ('inter your answer: '))
    else:
        print ('program is ok')
print ('you try %d \nyour level %d '%(count, level))
import random

list_a_p = ['+','-','*','/']
s = 0

def correct() :
    global s
    s += 1
    print('** correct **')
    print('-----------------')

def incorrect() :
    global s
    s -= 1
    print('** incorrect **')
    print('-----------------')

while True :
    a=random.randint(2,50)
    b=random.randint(2,10)
    a_p = random.choice(list_a_p)

    def Calculations() :
        if a_p == '+' and res == a+b :
            correct()

        elif a_p == '-' and res == a-b :
            correct()

        elif a_p == '*' and res == a*b :
            correct()

        elif a_p == '/' and res == a/b :
            correct()

        else : incorrect()

    if a_p == '/' and a % b != 0 : continue
    else :
        print('Enter # for exit : \n')
        print(f'{a} {a_p} {b}' , '=' ,end=' ')
        u_input = input().strip()

    if u_input == '#' :
        print("Exit .")
        break

    elif u_input == '' :
        incorrect()
        continue

    elif u_input.isalpha() :
        print("Error : Enter digits .")
        break

    elif u_input.isdigit() :
        print('-----------------')
        res = int(u_input)
        Calculations()

    elif u_input.find('.') != -1 :
        print('-----------------')
        res = float(u_input)
        Calculations()

    elif int(u_input) < 0 :
        print('-----------------')
        res = int(u_input)
        Calculations()

    else :
        print("Error : Enter digits .")
        break


print(f'Your score is {s}')
import time
from random import randint

start_time = time.time()
tedad_dorost = 0
tedad_khata = 0

while True:
  random1 = randint(1,15)
  if random1 == 1:
    computer = 20 + 20
    print("20 + 20 = ?")
  if random1 == 2:
    computer = 10 * 10
    print("10 * 10 = ?")
  if random1 == 3:
    computer = 20 * 6 
    print("20 * 6 = ?")
  if random1 == 4:
    computer = 30 - 30
    print("30 - 30 = ?")
  if random1 == 5:
    computer = 10 * 10
    print("10 * 10 = ?")
  if random1 == 6:
    computer = 30 * 2
    print("30 * 2 = ?")
  if random1 == 7:
    computer = 10 * 100
    print("10 * 100 = ?")
  if random1 == 8:
    computer = 15 / 3
    print("15 / 3 = ?")
  if random1 == 9:
    computer = 14 / 7
    print("14 / 7 = ?")
  if random1 == 10:
    computer = 10 / 10
    print("10 / 10 = ?")
  if random1 == 11:
    computer = 0 * 0
    print("0 * 0 = ?")
  if random1 == 12:
    computer = 5 * 5
    print("5 * 5 = ?")
  if random1 == 13:
    computer = 8 * 8
    print("8 * 8 = ?")
  if random1 == 14:
    computer = 9 * 9
    print("9 * 9 = ?") 
  if random1 == 15:
    computer = 256 * 2548
    print("256 * 2548 = ?") 



  player = int(input("enter your number:"))
  print(f"computer = {computer}")

  if player == computer:
    print("dorost")
    tedad_dorost = tedad_dorost + 1
  if player != computer:
    print("khata")
    tedad_khata = tedad_khata + 1
  if time.time() - start_time > 20:
    print("time up")
    break


print(f"tedad_dorost = {tedad_dorost}")
print(f"tedad_khata = {tedad_khata}")
if tedad_dorost > tedad_khata:
    print("player is win and computer is lose")
if tedad_khata > tedad_dorost:
    print("player is lose and computer is win")
import random
while True:
	T = []
	K = []
	g = random.randint(1, 100)
	h = random.randint(0, 100)
	T.append(g)
	K.append(h)
	O = tuple(T)
	D = tuple(K)
	W = sum(O)
	R = sum(D)
	Y = int(input(f"{T} +  {K} = "))
	if  (W + R) == (Y):
		print("درست :) برای رفتن به قسمت ضرب اشتباه وارد کنید")
	else:
		print( "اشتباه! وارد قسمت ضرب شدید")
		while True:
			Tt = []
			Kk = [] 
			gg = random.randint(1, 100)
			hh = random.randint(1, 100)
			Tt.append(gg)
			Kk.append(hh)
			Oo = tuple(Tt)
			Dd = tuple(Kk)
			Ww = sum(a * b for a, b in zip(Oo, Dd))
			Yy = int(input(f"{Tt} * {Kk} ="))
			if Ww == Yy:
				print("درست :) برای رفتن به قسمت تفریق اشتباه وارد کنید")
			else:
				print("اشتباه! وارد قسمت تفریق شدید")
				while True:
				
					ga = random.randint(1, 100)
					ha = random.randint(0, 100)
					Ta = [ga]
					Ka = [ha]
					Oa = tuple(Ta)
					Da = tuple(Ka)
				
					Ya = int(input(f"{ga} -  {ha} = "))
					if  ga - ha == (Ya):
						print("درست :) برای رفتن به قسمت جمع اشتباه وارد کنید")
					else:
						print( "اشتباه! وارد قسمت جمع شدید")
						break

from random import randint , choice
lis = ["*","+","-","/"]
char = choice(lis)
num1 = randint(1,10)
num2 = randint(1,10)

res = float(input(f"{num1} {char} {num2}: "))

if char not in lis:
print(f"Error , bayad horof az {lis} bashad.")

elif char == "*":
zarb = num1 * num2
if res == zarb:
print("Afarin doroste")
else:
print("Eshtebahe")

elif char == "+" :
jam = num1 + num2
if res == jam:
print("Afarin doroste")
else:
print("Eshtebahe")

elif char == "-":
tafrigh = num1 - num2
if res == tafrigh:
print("Afarin doroste")
else:
print("Eshtebahe")

elif char == "/" :
taghsim = num1 / num2
if res == taghsim:
print("Afarin doroste")
else:
print("Eshtebahe")

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن