🧮 ماشین حساب ساده با پایتون خب تا اینجا با چیزایی که یاد گرفتیم میتونیم یه ماشین حساب خیلی ساده بنویسیم که چهار عمل اصلی ریاضی یعنی جمع، تفریق ،ضرب و تقسیم رو انجام بده
مشاهده کد:
تمام موارد لازم در این مثال رو قبلا بصورت جدا توضیح دادیم، الان فقط اون ها رو ترکیب کردیم و یه ماشین حساب مبتدی ساختیم.
البته یه سری نکات هست که در ادامه توضیح میدم فعلا به این فکر کنید که چه چیزی میتونیم به این ماشین حساب اضافه کنیم که بهتر بشه؟! 
#آموزش _@ARCHLIN
operation = input("Select one oprator(+ or - or / or *) : ")
y = int(input("Enter second number : "))
if operation == "+":
addition = x + y
print(f"addition is : {addition}")
elif operation == "-":
subtraction = x - y
print(f"subtraction is : {subtraction}")
elif operation == "/":
division = x/y
print(f"division is : {division}")
elif operation =="*":
multiplication = x*y
print(f"multiplication is : {multiplication}")
else:
print("operation is incorrect !!!")
#آموزش _@ARCHLIN
۱۳:۲۷
x=int(input("Enter first number:"))
از عبارتx=input("Enter first number :")
استفاده می کردیم، در دستورات شرطی با خطا مواجه می شدیم. مثلا یکی از خطا ها این بود که برای عبارت 3+3 حاصل برابر می شد با 33
#آموزش _@ARCHLIN
۱۲:۴۳
#آموزش _@ARCHLIN
۲۰:۱۰
#آموزش _@ARCHLIN
۸:۱۰
🧮 ماشین حساب رو چطور بهتر کنیم؟
یکی از چیزای که میتونیم به ماشین حساب ساده قبلی اضافه کنیم حلقه while عه
مشاهده کد:
اینجوری محاسبات فقط برای دوتا عدد نیست و تا هرچقدر که بخوایم میتونیم از کاربر عدد بگیریم و جمع و تفریق و... انجام بدیم.
عدد اول رو بیرون از حلقه مینویسیم اما عملگر و عدد بعدی رو داخل حلقه میزاریم که چندین بار تکرار بشه
شرط حلقه هم اینجا True هست چون پایانی برای ماشین حساب در نظر نگرفتیم و میخوایم تا هر موقع که کاربر عدد وارد میکنه محاسبات انجام بشه
#آموزش _@ARCHLIN
while True:
operation = input("Select one oprator(+ or - or / or *) : ")
y = int(input("Enter second number : "))
if operation == "+":
x = x + y
print(f"result is : {x}")
elif operation == "-":
x = x - y
print(f"result is : {x}")
elif operation == "/":
x = x/y
print(f"result is : {x}")
elif operation =="*":
x = x*y
print(f"result is : {x}")
else:
print("operation is incorrect !!!")
#آموزش _@ARCHLIN
۱۷:۴۸
مثلا ما یه متغیر داریم به اسم «گوشی موبایل» که براش مدل های سامسونگ، اپل، هواوی و... داریم. با استفاده از لیست میتونیم همه برندها رو داخل یه متغیر ذخیره کنیم.
#آموزش _@ARCHLIN
۱۹:۲۳
#آموزش _@ARCHLIN
۱۰:۲۵
میتونیم عنصر دوم از لیست 1 رو چاپ کنیم. حالا چاپ کردن که فقط یه مثاله وگرنه شما وقتی با اندیس به عناصر لیست دسترسی داری میتونی هرکاری که مدنظرته انجام بدی!
#آموزش _@ARCHLIN
۱۶:۵۲
#آموزش _@ARCHLIN
۱۷:۵۹
رفقاااا سلااام
این چند روز درگیر یه پروژه ای بودم و خب نشد آموزش ها رو پیش ببریم🫠 فعلا علی الحساب موافقید بابت جبران این وقفه یه سورس بازی ببینیم؟
_@ARCHLIN
_@ARCHLIN
۱۱:۵۴
choices = ["Rock", "Paper", "Scissors"]
print("Welcome to Rock, Paper, Scissors!")
print("Choose one of the following: Rock, Paper, or Scissors.")
rounds = 3
player_score = 0
computer_score = 0
for round in range(1, rounds + 1):
print(f"\nRound {round}/{rounds}:")
player_choice = input("Enter your choice (Rock, Paper, or Scissors): ").capitalize()
if player_choice not in choices:
print("Invalid choice! Please choose Rock, Paper, or Scissors.")
continue
computer_choice = random.choice(choices)
print(f"Computer chose: {computer_choice}")
if player_choice == computer_choice:
print("It's a tie!")
elif (player_choice == "Rock" and computer_choice == "Scissors") or \
(player_choice == "Scissors" and computer_choice == "Paper") or \
(player_choice == "Paper" and computer_choice == "Rock"):
print(f"You win this round! {player_choice} beats {computer_choice}.")
player_score += 1
else:
print(f"You lose this round! {computer_choice} beats {player_choice}.")
computer_score += 1
print(f"\nFinal Score: You {player_score} - {computer_score} Computer")
if player_score > computer_score:
print("Congratulations! You won the game!")
elif player_score < computer_score:
print("Sorry! You lost the game. Better luck next time!")
else:
print("It's a draw! Well played!")
_@ARCHLIN۲۰:۲۵

پاکت هدیه
آرچلین💻☕
#آموزش _@ARCHLIN
۱۶:۵۳
#آموزش _@ARCHLIN
۱۷:۰۸