Pye3 S
Pye3 S
Pye3 S
Algorithm:
Code:
# Input a number from the user
number = float(input("Enter a number: "))
2. Develop a program to allows the users to enter a variable. Find the type of an
entered variable and display it.
Algorithm:
Code:
# Ask the user to enter a variable
user_input = input("Enter a variable: ")
3. Develop a program to find and display the sum of all numbers stored in a list.
Algorithm:
Code:
numbers = [1, 2, 3, 4, 5]
# Initialize sum to 0
sum = 0
4. Develop a program to demonstrate the use of the range function with for loop.
Code:
5. A. Develop a program to skip the “e” alphabet from the given string” engineering
that changes the world” and display it.
Algorithm:
Code:
#A
string = "engineering that changes the world"
result = ""
print(result)
#b
num = 1
6. Develop a program to find and display the sum of numbers entered by the user.
(if entered number is N then sum = 1+2+3+...+N)
Algorithm:
Code:
num = int(input("Enter a number: "))
sum = 0
i=1
7. Develop a program to allows the users to enter a fruit name. Based on the input
name, the program should search for it from the basket list and show its quantity
if the fruit is on the list. If the fruit is not found, the while loop is terminated
normally and the else clause will be executed to add a new fruit to the list.
Algorithm:
Code:
basket = {
"apple": 5,
"banana": 3,
"orange": 2
}
if add_fruit.lower() == "yes":
quantity = int(input("Enter the quantity: "))
basket[fruit] = quantity
break
else:
print(f"The quantity of {fruit} in the basket is
{basket[fruit]}")
Conclusion:
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________