Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . some of the simple python programs | GreatToCode

some of the simple python programs | GreatToCode

Become More Then A coder | Learn & Start Coding Now.

python program to print hello world !

print ('Hello ,World '!)

In this program we have used the built in print () function to print the string Hello, World ! on our screen .
by the way string is the way to sequence of the character . In python string are enclosed  inside the single quote, double quote or triple quote .

python program to add two numbers ! 

we will use the + operator to add two numbers .

Example 1. Add Two numbers 

#This program add two numbers 
num1= 2
num2 =3 

#add two numbers 
sum = num1 +  num2 

#Display the sum 
print ( 'The sum of the {0} and {1} is {2} '   .format (num1, num2 , sum ) )

Example 2. Add two numbers with the user Input 

#store input numbers 
num1 = input (' Enter first number: ')
num2 = input (' Enter second number: ')
 # Add two numbers 
Sum= float (num1)  + float (num2)

#display the sum 
print('The sum OF THE {0} and {1} is {2}' .format(num1 , num2 , sum ) )

output 

Enter first number: 2
Enter second number 3
The sum of the 2 and 3 is 5 

In this program we asked the user to Enter two numbers and this program display the sum of the two numbers entered by the users . 
We Use Built -in function input () to take the input . since input () returns a string , We convert the string into number using the float () function . then the number are added .

here is alternative of the above -


print('The sum is %.1f' %(float(input('Enter first number: ')) + float(input('Enter second number: '))))
print('The sum is %.If %(float(input('Enter first number:'))+ float(input('Enter second number:'))))

Output 

Enter the first number: 4
Enter the second number: 6 
the sum of 4 and 6 is 10 .


Although the program uses no variables ( memory efficient ) it is harder to read.


PYTHON PROGRAM TO FIND THE SQUARE ROOT

Example : for positive numbers 

#python program to calculate the square root 

#Note: change this value for the different results .

num=6
#To take the input from the user

#num = float (input ('Enter a number: ') )

num_sqrt =num **  0.5 

print ('The square root of % 0.3f  is % 0.3f' % (num , num_sqrt )) 


output 

The square root of the 6.000 is  2.828 


In this program we store the number in num  and find the square root using the ** exponent operator .
this program work on the all the positive real numbers . 
















Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.