الرئيسية chevron_left الأسئلة chevron_left CSS Height chevron_left CSS
																			
											
												 num1 = float(input("please enter the first number: ")) operator = input("please enter the operator: ") num2 = float(input("please enter the second number: ")) if operator == "+": print("num1 + num2") elif operator == "-": print("num1 - num2") elif operator == "/": print("num1 / num2") elif operator == "*": print("num1 * num2") else: print("wrong operator please try again")  ما الخطا في هذا الكود بلغة python
  
											
										
									
									
										num1 = float(input("please enter the first number: ")) operator = input("please enter the operator: ") num2 = float(input("please enter the second number: ")) if operator == "+": print("num1 + num2") elif operator == "-": print("num1 - num2") elif operator == "/": print("num1 / num2") elif operator == "*": print("num1 * num2") else: print("wrong operator please try again")  ما الخطا في هذا الكود بلغة python
									
								
							 
  
											
										num1 = float(input("please enter the first number: ")) operator = input("please enter the operator: ") num2 = float(input("please enter the second number: ")) if operator == "+": print("num1 + num2") elif operator == "-": print("num1 - num2") elif operator == "/": print("num1 / num2") elif operator == "*": print("num1 * num2") else: print("wrong operator please try again") ما الخطا في هذا الكود بلغة python ؟
 
							الرد التلقائي
من
CLOSETAG
19 يونيو 2023
لا يوجد خطأ صرفي في الكود، لكن هناك خطأ منطقي في الجمل الشرطية، إذ أنه يجب استخدام قيم المتغيرات num1 وnum2 داخل عمليات الجمع والطرح والقسمة والضرب، ولكن الجمل الشرطية تقوم بطباعة نصوص ثابتة بدلاً من القيم الفعلية. لذلك يجب استخدام قيم المتغيرات في هذه الجمل بدلاً من كتابة النص الثابت. 
الكود الصحيح هو كالتالي:
num1 = float(input("please enter the first number: "))
operator = input("please enter the operator: ")
num2 = float(input("please enter the second number: "))
if operator == "+":
   print(num1 + num2)
elif operator == "-":
   print(num1 - num2)
elif operator == "/":
   print(num1 / num2)
elif operator == "*":
   print(num1 * num2)
else:
   print("wrong operator please try again")
								 
                           
																	 CLOSETAG
                            CLOSETAG
                        