INDEX
- Simple Hello Python program
- Python program: Average of 2 (two) integers
- Python program: Celsius (or Centigrade) to Fahrenheit conversion
- Python program: SWAP PROGRAM (Using 3rd Variable)
- Python program: SWAP PROGRAM (Without Using 3rd Variable)
- Python program: Accept first name, middle name and lastname seperately and then display the full name.
- Python program: Compound Interest calculation.
- Python program: Aceept marks in five subjects - English, Physics, Chemistry, Mathematics, Computers and display the total marks and percentage
print("Hello!!! Welcome to Python")
Note:
In Python strings can also be enclosed as follows:
Using Single Qoutes as: 'Hello!!! Welcome to Python'
Using Tripple Double Qoutes as: """Hello!!! Welcome to Python"""
Using Tripple Single Qoutes as: '''Hello!!! Welcome to Python'''
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners //Python Program: Accept two integers and display their average
a=int(input("Enter 1st ineteger: "))
b=int(input("Enter 2nd integer: "))
c=(a+b)/2
print("The Average of " + str(a) + " and " + str(b) + " is = " + str(c))
Note:
int(number as string or number), float(number as string or number), str(number or object)
The above are explicit type casting functions used to return the specified equivalent of passed argument
Ex: The function int(number as string or number) returns the integer-equivalent of the passed argument,
the argument to int() could be a number of any valid datatype or could be a number written/saved as string.
input(prompt as sring) method displays the specified prompt/message on the screen, accepts the user input through K/B as string and returns it.
The + operator in the print() method concatenates two strings.
Alternatively, a better approach is:
print("The Average of ",a," and ",b," is = ",c)
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners //Python Program: A program to aceept temperature in degree celsius and displays its farenheit equivalent
c=float(input('Enter teperature in degree Celsius: '))
f=(9*c)/5+32
print(str(c)+' degree Celsius = ' + str(f) + ' degree fahrenheit. ');
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners /*Python Program: SWAP PROGRAM (Using 3rd Variable): Accept two integers, excahnge their values and then display their new values.
example:
Enter Integer1: 5
Enter Integer2: 7
Values Before Swap/Exchange: Integer1: 5 and Integer2: 7
Values After Swap/Exchange: Integer1: 7 and Integer2: 5
*/
a=int(input('Enter Integer 1: '))
b=int(input('Enter Integer 2: '))
print('Values Before swap/exchange: Integer1: ' + str(a) + ' and Integer2: ' + str(b))
c=a
a=b
b=c
print('Values After swap/exchange: Integer1: ' + str(a) + ' and Integer2: ' + str(b))
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners /*Python Program: SWAP PROGRAM (Without Using 3rd Variable): Accept two integers, excahnge their values and then display their new values.
example:
Enter Integer1: 5
Enter Integer2: 7
Values Before Swap/Exchange: Integer1: 5 and Integer2: 7
Values After Swap/Exchange: Integer1: 7 and Integer2: 5
*/
a=int(input('Enter Integer 1: '))
b=int(input('Enter Integer 2: '))
print('Values Before swap/exchange: Integer1: ' + str(a) + ' and Integer2: ' + str(b))
a=a+b
b=a-b
a=a-b
print('Values After swap/exchange: Integer1: ' + str(a) + ' and Integer2: ' + str(b))
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners /*Python Program: Accept first name, middle name and lastname seperately and then display the full name
example:
Enter First Name: Sachin
Enter Middle Name: Ramesh
Enter Last Name: Tendulkar
Full Name: Sachin Ramesh Tendulkar
*/
fname=input('Enter First Name: ')
mname=input('Enter Middle Name: ')
lname=input('Enter Last Name: ')
print('Full Name: ' + fname + ' ' + mname + ' ' + lname)
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners /*Python Program: Accept principal, rate of interest and time period, then display the compound interest and the amount earned.
example:
Principal Money: 1000
Rate of Interest(per annum): 10
Time period (in years): 3
Calculating for Interest Compounded Annually
Interest Earned: 331
Amount: 1331
*/
p=float(input('Principal Money: '))
r=float(input('Rate of interest (per annum): '))
t=float(input('Time period (in years): '))
print('Calculating for Interest Compounded Annually ...')
amt=p*((1+r/100)**t)
ci=amt-p
print('Interest Earned: ',ci,'\nAmount: ',amt)
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners /*Python Program: A program to aceept marks of a student in five subjects - English, Physics, Chemistry, Mathematics, Computers
and then display the total marks and percentage. Assuming maximum marks for each subject is 80.*/
print('Enter the Marks in Respective Subjects.')
eng=float(input('ENGLISH (out of 80): '))
phy=float(input('PHYSICS (out of 80): '))
chem=float(input('CHEMISTRY (out of 80): '))
math=float(input('MATHEMATICS (out of 80): '))
comp=float(input('COMPUTER (out of 80): '))
total=eng+phy+chem+math+comp
percent=total*100/400
print('Total Marks(out of 400): ',total,'\nPercentage Secured: ',percent,'%')
Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners | Python Programming | Computer Programming for Beginners