



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




#Write a Python program to print numbers from 1 to 20 print("Generating numbers from 1 to 20") for i in range( 1 , 21 ): print(i, end=" ")
Generating numbers from 1 to 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#To convert Temperature from Fahrenheit (โ) to Celsius (โ). f = int(input("Enter the temperature in GFarehait:")) c = (f- 32 )* 5 / 9 print(f, "farenheit is = ",round(c,2),"Celsius")
Enter the temperature in GFarehait: 40 farenheit is = 4.44 Celsius
#program to implement working of the traffic signal with appropriate message. sig= input("Enter the color(Red/Green/yellow):") print("Traffic Signal Message display") if sig == "Red": print("Stop your Vehicle") elif sig == "Green": print("Move your Vehicle") elif sig =="Yellow": print("Slow Down your Vehicle") else: print("Invalid Color")
Enter the color(Red/Green/yellow):Yellow Traffic Signal Message display Slow Down your Vehicle
b=float(input("Enter the balance:")) print("\n--- ATM Menu ---") print("1. Check Balance") print("2. Deposit") print("3. Withdraw") print("4. Exit") choice = input("Enter your choice (1-4): ") if choice == '1': print("Your balance is:", b) elif choice == '2': amount = float(input("Enter the amount to deposit: ")) b += amount print("Your new balance is:", b) elif choice == '3': amount = float(input("Enter the amount to withdraw: ")) if amount > b: print("Insufficient balance") else: b - = amount print("Your new balance is:", b) elif choice == '4': print("Thank you for using the ATM") else: print("Invalid choice")
Enter the balance: --- ATM Menu ---
#program to calculate the average of three subjectsโ marks. a=int(input("enter the marks of English:")) b=int(input("enter the marks of Math:")) c=int(input("enter the marks of Science:")) avg=(a+b+c)/ 3 print("The average marks of three subjects is:",round(avg, 2 ))
enter the marks of English: enter the marks of Math: enter the marks of Science: The average marks of three subjects is: 90.
#Program to create a list of 5 tourist places tp1=["Eiffel Tower","Burj Khalifa"] tp2=["Taj Mahal","Great Wall of China"] print("Tourist places List1 :",tp1) print("Tourist places List1 :",tp2) tp1.extend(tp2) print() print("The updated List is:",tp1) new_tp=input("Enter a new tourist place:") tp1.append(new_tp) print() print("The updated List using append is:",tp1) new_tp=input("Enter a new tourist place to insert in 3 position:") tp1.insert( 2 ,new_tp) print() print("The updated List using insert is:",tp1) tp1.pop( 1 ) print() print("The updated List after poping 2nd element is:",tp1) tp1.remove("Taj Mahal") print() print("The updated List after using remove is:",tp1)
Tourist places List1 : ['Eiffel Tower', 'Burj Khalifa'] Tourist places List1 : ['Taj Mahal', 'Great Wall of China'] The updated List is: ['Eiffel Tower', 'Burj Khalifa', 'Taj Mahal', 'Great Wall of China'] Enter a new tourist place:Bali The updated List using append is: ['Eiffel Tower', 'Burj Khalifa', 'Taj Mahal', 'Great Wall of China', 'Bali'] Enter a new tourist place to insert in 3 position:Petra The updated List using insert is: ['Eiffel Tower', 'Burj Khalifa', 'Petra', 'Taj Mahal', 'Great Wall of China', 'Bali'] The updated List after poping 2nd element is: ['Eiffel Tower', 'Petra', 'Taj Mahal', 'Great Wall of China', 'Bali'] The updated List after using remove is: ['Eiffel Tower', 'Petra', 'Great Wall of China', 'Bali']
#program to add the elements of the two lists. import numpy as np a=[ 10 , 20 , 30 , 40 ] b=[ 50 , 60 , 70 , 80 ] print("List1:",a) print("List2:",b) c=np.add(a,b) result=c.tolist() print("The updated List is:",result)
List1: [10, 20, 30, 40] List2: [50, 60, 70, 80] The updated List is: [60, 80, 100, 120]