إنشاء آلة حاسبة
يدور هذا الدرس حول مثال لمشروع بايثون: آلة حاسبة بسيطة.
يشرح كل جزء قسمًا مختلفًا من البرنامج.
القسم الأول هو القائمة الشاملة. يستمر هذا في قبول إدخال المستخدم حتى يدخل المستخدم "quit" ، لذلك يتم استخدام حلقة while.
while True:
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter 'subtract' to subtract two numbers")
print("Enter 'multiply' to multiply two numbers")
print("Enter 'divide' to divide two numbers")
print("Enter 'quit' to end the program")
user_input = input(": ")
if user_input == "quit":
break
elif user_input == "add":
...
elif user_input == "subtract":
...
elif user_input == "multiply":
...
elif user_input == "divide":
...
else:
print("Unknown input")
إنشاء آلة حاسبة
يدور هذا الدرس حول مثال لمشروع بايثون: آلة حاسبة بسيطة.
يشرح كل جزء قسمًا مختلفًا من البرنامج.
القسم الأول هو القائمة الشاملة. يستمر هذا في قبول إدخال المستخدم حتى يدخل المستخدم "quit" ، لذلك يتم استخدام حلقة while.
The code above is the starting point for our program. It accepts user input, and compares it to the options in the if/elif statements.
The break statement is used to stop the while loop, in case the user inputs "quit".
الرمز أعلاه هو نقطة البداية لبرنامجنا. يقبل إدخال المستخدم ومقارنتها بالخيارات الموجودة في عبارات if / elif.
يتم استخدام العبارة break لإيقاف حلقة while ، في حالة قيام المستخدم بإدخال "quit" (إنهاء).
يشرح كل جزء قسمًا مختلفًا من البرنامج.
القسم الأول هو القائمة الشاملة. يستمر هذا في قبول إدخال المستخدم حتى يدخل المستخدم "quit" ، لذلك يتم استخدام حلقة while.
while True:
print("Options:")
print("Enter 'add' to add two numbers")
print("Enter 'subtract' to subtract two numbers")
print("Enter 'multiply' to multiply two numbers")
print("Enter 'divide' to divide two numbers")
print("Enter 'quit' to end the program")
user_input = input(": ")
if user_input == "quit":
break
elif user_input == "add":
...
elif user_input == "subtract":
...
elif user_input == "multiply":
...
elif user_input == "divide":
...
else:
print("Unknown input")
إنشاء آلة حاسبة
يدور هذا الدرس حول مثال لمشروع بايثون: آلة حاسبة بسيطة.
يشرح كل جزء قسمًا مختلفًا من البرنامج.
القسم الأول هو القائمة الشاملة. يستمر هذا في قبول إدخال المستخدم حتى يدخل المستخدم "quit" ، لذلك يتم استخدام حلقة while.
The code above is the starting point for our program. It accepts user input, and compares it to the options in the if/elif statements.
The break statement is used to stop the while loop, in case the user inputs "quit".
الرمز أعلاه هو نقطة البداية لبرنامجنا. يقبل إدخال المستخدم ومقارنتها بالخيارات الموجودة في عبارات if / elif.
يتم استخدام العبارة break لإيقاف حلقة while ، في حالة قيام المستخدم بإدخال "quit" (إنهاء).
ليست هناك تعليقات: