0% found this document useful (0 votes)
31 views5 pages

Python Programs With Out

The document contains several Python programs with their outputs, including a menu-based calculator, an Armstrong number checker, and a program to find the minimum and maximum in a list. It also features a lottery guess game, a random dice simulation, and a Fibonacci series generator. Each program includes sample input and output for clarity.

Uploaded by

rohanmurali8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views5 pages

Python Programs With Out

The document contains several Python programs with their outputs, including a menu-based calculator, an Armstrong number checker, and a program to find the minimum and maximum in a list. It also features a lottery guess game, a random dice simulation, and a Fibonacci series generator. Each program includes sample input and output for clarity.

Uploaded by

rohanmurali8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Python Programs with Output

========================
1. MENU-BASED CALCULATOR
========================
val1 = float(input("Enter the first value: "))
val2 = float(input("Enter the second value: "))
while True:
choice =
int(input("MENU\n1->ADDITION\n2->SUBTRACTION\n3->MULTIPLICATION\n4->DIVISION\n5->FLOOR
DIVISION\n6->REMAINDER\n7->EXIT\nENTER YOUR CHOICE: "))
if choice == 1:
result = val1 + val2
elif choice == 2:
result = val1 - val2
elif choice == 3:
result = val1 * val2
elif choice == 4:
if val2 == 0:
print("Please enter a value other than 0")
else:
result = val1 / val2
elif choice == 5:
result = val1 // val2
elif choice == 6:
result = val1 % val2
else:
break
print("The result is:", result)

Sample Output:
Enter the first value: 10
Enter the second value: 5
MENU
1->ADDITION
2->SUBTRACTION
3->MULTIPLICATION
4->DIVISION
5->FLOOR DIVISION
6->REMAINDER
7->EXIT
ENTER YOUR CHOICE: 1
The result is: 15.0

Page 1
Python Programs with Output

============================
2. ARMSTRONG NUMBER CHECKER
============================
n = int(input("Enter number to check for Armstrong number: "))
x = n
sum = 0
while n > 0:
r = n % 10
sum = sum + r**3
n = n // 10
print("\nSum of the numbers:", sum)
if x == sum:
print("Armstrong number")
else:
print("Not an Armstrong number")

Sample Output:
Enter number to check for Armstrong number: 153
Sum of the numbers: 153
Armstrong number

============================
3. MINIMUM AND MAXIMUM IN LIST
============================
a = int(input("Enter the number of values you want to input: "))
L = []
for i in range(a):
b = int(input(f"Enter number {i+1}: "))
L.append(b)
print("\nCurrent values in the list are:")
print(L)
print("\nThe Minimum element of the list is:", min(L))
print("The Maximum element of the list is:", max(L))

Sample Output:
Enter the number of values you want to input: 5
Enter number 1: 4
Enter number 2: 10
Enter number 3: 6
Enter number 4: 3
Enter number 5: 8

Page 2
Python Programs with Output

Current values in the list are:


[4, 10, 6, 3, 8]
The Minimum element of the list is: 3
The Maximum element of the list is: 10

===========================
4. LARGEST OF THREE NUMBERS
===========================
A = int(input("Enter the first number: "))
B = int(input("Enter the second number: "))
C = int(input("Enter the third number: "))
if A >= B and A >= C:
print("LARGEST NUMBER:", A)
elif B >= A and B >= C:
print("LARGEST NUMBER:", B)
else:
print("LARGEST NUMBER:", C)

Sample Output:
Enter the first number: 5
Enter the second number: 12
Enter the third number: 9
LARGEST NUMBER: 12

====================
5. LOTTERY GUESS GAME
====================
import random
n = random.randint(1, 6)
guess = int(input("Enter number between 1 and 6: "))
if n == guess:
print("CONGRATULATIONS! YOU HAVE WON THE LOTTERY!!")
else:
print("SORRY:(TRY AGAIN)")
print("THE LUCKY NUMBER WAS", n)

Sample Output:
Enter number between 1 and 6: 3
SORRY:(TRY AGAIN)
THE LUCKY NUMBER WAS 5

=============================

Page 3
Python Programs with Output

6. RANDOM DICE SIMULATION GAME


=============================
import random
import time
print("PRESS CTRL+C to stop the dice")
play = input("Wish to play (y/n)? ")
while play == 'y':
try:
while True:
for i in range(2):
print()
n = random.randint(1, 6)
print(n, end=" ")
time.sleep(0.05)
except KeyboardInterrupt:
print("Your number:", n)
ans = input("Wish to play more (y/n)? ")
if ans.lower() != 'y':
play = 'n'
break

Sample Output:
(Continuously prints numbers until Ctrl+C is pressed)

==========================
7. FIBONACCI SERIES GENERATOR
==========================
i = int(input("Enter the Limit: "))
x = 0
y = 1
z = 1
print("Fibonacci Series:")
print(x, end=" ")
print(y, end=" ")
while z <= i:
print(z, end=" ")
x = y
y = z
z = x + y

Sample Output:
Enter the Limit: 15

Page 4
Python Programs with Output

Fibonacci Series:
0 1 1 2 3 5 8 13

Page 5

You might also like