بررسی قضیه حمار
برنامه ای بنویسید که با گرفتن ۳ ورودی ار کاربر بررسی کند که با توجه به قضیه حمار میتوان مثلثی با ضلع های دریافت شده ساخت یا خیر؟
(قضیه حمار یا نابرابری مثلثی: در هر مثلث اندازه هر ضلع از مجموع ۲ ضلع دیگر کوچکتر است)
برنامه ای بنویسید که با گرفتن ۳ ورودی ار کاربر بررسی کند که با توجه به قضیه حمار میتوان مثلثی با ضلع های دریافت شده ساخت یا خیر؟
(قضیه حمار یا نابرابری مثلثی: در هر مثلث اندازه هر ضلع از مجموع ۲ ضلع دیگر کوچکتر است)
a = int(input("enter your number:")) b = int(input("enter your number:")) c = int(input("enetr your number:")) if a + b > c or a + c > b or b + c > a: print("mosallas nist") else: print("mollass mibashad")
X=float(input("x:")) Y=float(input("y:")) H=float(input("h:")) if X<Y+H and Y<X+H and H<X+Y: print("قضیه حمار برقرار است") else: print("نمی توان با این اعداد مثلثی ساخت")
fS=str(input("enter the first side:")) sS=str(input("enter the secend side")) tS=str(input("enter the third side")) if (fs+sS)>tS and (fS+tS)>sS and (sS+tS)>fS: print("you can make a triangle with these sides") else: print("you cant make a triangle with these sides")
a=int(input("Enter a number: ")) b=int(input("Enter another number: ")) c=int(input("Enter a third number: ")) if a+b>c: print("true") elif a+c>b: print("true") elif b+c>a: print("true") elif c+a>b: print("true") else: print("false")
import time strat_time = time.time() while True: a = int(input("enter your number a:")) if a == 0: print("finish") break b = int(input("enter your number b:")) c = int(input("enter your number c:")) if a < b + c or b < a + c or c < a + b: print("homar bargharar ast") if a == b == c: print("not homar") if time.time() - strat_time > 7: print("time is over") break روش دوم هستش
a =int(input("pls enter the first number;....." )) b = int(input("pls second number :) ....")) c = int(input("pls and the last number....")) if a < b+c and b< a+c and c< a+b : print("great! The inserted sides are without problems/..") else: print("sorry, you can't make triangle ): ")
def can_form_triangle(a, b, c): """بررسی میکند که آیا میتوان مثلثی با اضلاع a، b و c ساخت یا خیر.""" return (a + b > c) and (a + c > b) and (b + c > a) if __name__ == "__main__": # دریافت اندازه اضلاع مثلث از کاربر while True: try: a = float(input("لطفاً اندازه ضلع اول مثلث را وارد کنید: ")) b = float(input("لطفاً اندازه ضلع دوم مثلث را وارد کنید: ")) c = float(input("لطفاً اندازه ضلع سوم مثلث را وارد کنید: ")) break except ValueError: print("لطفاً یک عدد صحیح یا اعشاری وارد کنید.") # بررسی اینکه آیا مثلث میتوان ساخت یا خیر if can_form_triangle(a, b, c): print("با این اضلاع میتوان مثلثی ساخت.") else: print("با این اضلاع نمیتوان مثلثی ساخت.")
# بررسی قضیه حمار
a=int(input("a: "))
b=int(input("b: "))
c=int(input("c: "))
if (a+b>c) and (a+c>b) and (b+c>a) :
print("we can make triangle")
else:
print("we nca not make triangle")
x1=int(input("print your x1: ")) x2=int(input("print your x2: ")) x3=int(input("print your x3: ")) if x1+x2>x3 and x2+x3>x1 and x3+x1>x2: print("True") else: print("False")
# قضیه حمار
def is_valid_side(r: float) -> bool:
"""Checks if a side length is valid (greater than zero)."""
if r <= 0:
print(f"The side length must be greater than zero.")
return False
return True
def get_sides():
"""Gets three valid positive side lengths from the user."""
while True:
try:
a1 = float(input("Enter the length of the first side of the triangle: "))
if not is_valid_side(a1):
continue
b2 = float(input("Enter the length of the second side of the triangle: "))
if not is_valid_side(b2):
continue
c3 = float(input("Enter the length of the third side of the triangle: "))
if not is_valid_side(c3):
continue
# If all sides are valid, break the input loop and return
return a1, b2, c3
except ValueError:
print("Please enter a valid number.")
def Hemar(a: float, b: float, c: float):
"""Checks if sides form a triangle and prints the result."""
if (a + b > c) and (a + c > b) and (b + c > a):
print(f" You can make a triangle with sides {a}, {b} and {c}.")
else:
print(f" You can't make a triangle with sides {a}, {b} and {c}.")
# Main program loop
while True:
# Get valid sides from the user
side1, side2, side3 = get_sides()
# Check if they form a triangle and print the result
Hemar(side1, side2, side3)
# Ask if the user wants to restart
while True:
restart = input("Do you want to Enter again? (y/n): ")
if restart.lower() == "y":
break # Break the inner loop to continue the outer loop
elif restart.lower() == "n":
print("Thank you for using our program.")
exit() # Exit the program
else:
print("Please enter a valid input.")
تابعی بنویسید که 2 رشته دریافت کند و رشته دوم را در رشته اول جستجو کند. اگر در رشته اول، رشته دوم وجود داشت True و در غیر اینصورت False را برگرداند نکته: برای جستجو نباید از تابع های آماده استفاده ...
تابعی بنویسید که عددی دریافت کند و اگر آن عدد، عدد اول بود True و در غیر این صورت False برگرداند
برنامه ای بنویسید که یک متن از کاربر به عنوان ورودی دریافت کند و تمام کلماتی که در متن استفاده شده، به همراه تعداد تکرار آنها را به کاربر نمایش دهدمثال:input: This is an example. This is a text... ...
تابعی بنویسید که یک لیست از اعداد دریافت کند و 2 لیست برای اعداد زوج و فرد آن ایجاد کرده و در خروجی چاپ کند مثالmyfun([1,2,3,4]) output: [1,3] [2,4]
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام
اگه متوجه تمرین نمیشی یا به هر دلیلی نمیتونی حلش کنی، کاملا طبیعیه، اشکالی نداره؛ ناراحت نشو
😊
سعی کن تمرینات آسون تر رو ببینی و جواب های مختلفی که دیگران ارسال کرده اند رو بررسی کنی و
یواش یواش به سراغ تمرینات سخت تر بری.
همچنین ممکنه جوابت درست باشه ولی با سایر جواب ها متفاوت باشه
اگه برنامه نویسی رو هنوز شروع نکردی یا خوب یاد نگرفتی، میتونی از طریق لینک زیر یاد بگیری