Write 20 Simple Basic Python Programs With Output - Search
Write 20 Simple Basic Python Programs With Output - Search
num1 = 5
num2 = 7
sum = num1 + num2
print("Sum of {0} and {1} is {2}".format(num1, num2, sum))
Output:
Sum of 5 and 7 is 12
num = 16
sqrt = num ** 0.5
print("Square root of {0} is {1}".format(num, sqrt))
Output:
Square root of 16 is 4.0
base = 10
height = 5
area = 0.5 * base * height
print("Area of the triangle is {0}".format(area))
Output:
Area of the triangle is 25.0
length = 10
breadth = 5
area = length * breadth
print("Area of the rectangle is {0}".format(area))
Output:
Area of the rectangle is 50
https://www.bing.com/search?pglt=673&q=write+20+simple+basic+python+programs+with+output&cvid=599dc6aafd8f4617b39c07a1df63a5bd&… 1/4
12/1/23, 8:07 PM write 20 simple basic python programs with output - Search
Python
AI-generated code. Review and use carefully. More info on FAQ.
radius = 5
pi = 3.14
circumference = 2 * pi * radius
print("Circumference of the circle is {0}".format(circumference))
Output:
Circumference of the circle is 31.400000000000002
radius = 5
pi = 3.14
area = pi * radius ** 2
print("Area of the circle is {0}".format(area))
Output:
Area of the circle is 78.5
celsius = 37.5
fahrenheit = (celsius * 1.8) + 32
print("{0} degree Celsius is equal to {1} degree Fahrenheit".format(celsius,
fahrenheit))
Output:
37.5 degree Celsius is equal to 99.5 degree Fahrenheit
fahrenheit = 99.5
celsius = (fahrenheit - 32) / 1.8
print("{0} degree Fahrenheit is equal to {1} degree
Celsius".format(fahrenheit, celsius))
Output:
99.5 degree Fahrenheit is equal to 37.5 degree Celsius
https://www.bing.com/search?pglt=673&q=write+20+simple+basic+python+programs+with+output&cvid=599dc6aafd8f4617b39c07a1df63a5bd&… 2/4
12/1/23, 8:07 PM write 20 simple basic python programs with output - Search
num = -5
if num > 0:
print("{0} is a positive number".format(num))
elif num == 0:
print("{0} is zero".format(num))
else:
print("{0} is a negative number".format(num))
Output:
-5 is a negative number
num = 7
if num % 2 == 0:
print("{0} is even".format(num))
else:
print("{0} is odd".format(num))
Output:
7 is odd
year = 2024
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
Output:
2024 is a leap year
num1 = 5
num2 = 7
num3 = 3
if num1 >= num2 and num1 >= num3:
https://www.bing.com/search?pglt=673&q=write+20+simple+basic+python+programs+with+output&cvid=599dc6aafd8f4617b39c07a1df63a5bd&… 3/4
12/1/23, 8:07 PM write 20 simple basic python programs with output - Search
largest = num1
elif num2 >= num1 and num2 >= num3:
largest = num2
else:
largest = num3
print("The largest number is {0}".format(largest))
Output:
The largest number is 7
num1 = 5
num2 = 7
num3 = 3
if num1 <= num2 and num1 <= num3:
smallest
https://www.bing.com/search?pglt=673&q=write+20+simple+basic+python+programs+with+output&cvid=599dc6aafd8f4617b39c07a1df63a5bd&… 4/4