প্রোগ্রামিংয়ের মৌলিক ধারণা/পাইথন শর্তের উদাহরণ
অবয়ব
তাপমাত্রা
[সম্পাদনা]#এই প্রোগ্রামটি ব্যবহারকারীকে ফারেনহাইট বা সেলসিয়াস রূপান্তর নির্বাচন করতে বলে
#এবং একটি নির্দিষ্ট তাপমাত্রা ইনপুট করতে বলে। তারপর প্রোগ্রামটি প্রদত্ত
#তাপমাত্রা রূপান্তর করে ফলাফল প্রদর্শন করে।
#
# তথ্যসূত্র:
# https://www.mathsisfun.com/temperature-conversion.html
# https://en.wikibooks.org/wiki/Java_Programming
def get_choice():
print("সেলসিয়াসে রূপান্তর করতে C অথবা ফারেনহাইটে রূপান্তর করতে F লিখুন:")
choice = input()
return choice
def get_temperature(label):
print(f"{label} তাপমাত্রা লিখুন:")
temperature = float(input())
return temperature
def calculate_celsius(fahrenheit):
celsius = (fahrenheit - 32) * 5 / 9
return celsius
def calculate_fahrenheit(celsius):
fahrenheit = celsius * 9 / 5 + 32
return fahrenheit
def display_result(temperature, from_label, result, to_label):
print(f"{temperature}° {from_label} হল {result}° {to_label}")
def main():
choice = get_choice()
if choice == "C" or choice == "c":
temperature = get_temperature("ফারেনহাইট")
result = calculate_celsius(temperature)
display_result (temperature, "ফারেনহাইট", result, "সেলসিয়াস")
elif choice == "F" or choice == "f":
temperature = get_temperature("সেলসিয়াস")
result = calculate_fahrenheit(temperature)
display_result (temperature, "সেলসিয়াস", result, "ফারেনহাইট")
else:
print("আপনাকে সেলসিয়াসে রূপান্তর করতে C অথবা ফারেনহাইটে রূপান্তর করতে F লিখতে হবে।")
main()
আউটপুট
[সম্পাদনা]সেলসিয়াসে রূপান্তর করতে C অথবা ফারেনহাইটে রূপান্তর করতে F চাপুন: c ফারেনহাইট তাপমাত্রা দিন: 100 100° ফারেনহাইট হল 37.7777777777778° সেলসিয়াস সেলসিয়াসে রূপান্তর করতে C অথবা ফারেনহাইটে রূপান্তর করতে F চাপুন: f সেলসিয়াস তাপমাত্রা দিন: 100 100° সেলসিয়াস হল 212° ফারেনহাইট সেলসিয়াসে রূপান্তর করতে C অথবা ফারেনহাইটে রূপান্তর করতে F চাপুন: x আপনাকে সেলসিয়াসে রূপান্তর করতে C অথবা ফারেনহাইটে রূপান্তর করতে F চাপতে হবে!