Python Exp 1
Python Exp 1
Name: M. KARTHIK
Aim:
Algorithm:
Program:
Output:
Result:
The program is successfully printed and the sum of the squares of the numbers in the list are displayed as output.
2.Program to print the sum of first 5 natural numbers
Aim:
Algorithm:
Step 4: Using for loop declare add each time the number to the sum.
Program:
Output:
Result:
The program is successfully executed and the sum of the first 5 natural numbers are displayed as output.
3. Program to print table of given number using for loops
Aim:
Algorithm:
Step 2: Get the input from the user and assign it to a variable name table.
Program:
Output:
Result:
The program is successfully executed and the table for the given number is displayed as output.
4.Simulate a guessing the number game using while loops.
Aim:
Algorithm:
Step 2: Get the input from the user and assign it to a variable name guess.
Step 4: Use while loop and use If / else condition and specify the conditions to it.
Program:
Output:
Result:
The program is successfully executed and the guess the number game is displayed as output.
5. Write a Python program to construct the following pattern, using a nested for
loop.
**
***
****
*****
**
***
****
*****
****
***
**
Aim:
Algorithm:
Step 2: Use for nested loop and give range as (0,5) and (0,i+1) .
Step 3: print ‘ * ‘
Step 4: Tp display next symbol use the previous code for the first half of the symbol and for next half edit the old
code and add print * at last.
a)
b)
Output:
a)
b)
Result:
b) Count the number of even and odd numbers from a series of numbers
c) Write a Python program which iterates the integers from 1 to 50. For
multiples of three print & ‘Department’. instead of the number and for
the multiples of five print &’CSE&’. For numbers which are multiples of
Aim:
Algorithm:
Step 2: Get the input from the user and assign it to a variable name number.
Step 3: Use If / else conditions and specify the conditions given in the question.
Step 4: for part b) get the limit from the user and increment the value of c in sum is even and else c2. And finally
print the c and c2
Step 5: For part c) Use the for loop and inside that loop use if / else condition and give the condition accourdingly.
Program:
a)
b)
c)
Output:
a)
b)
c)
Result: