0% found this document useful (0 votes)
92 views

Python Exp 1

The document contains details of a Python programming assignment submitted by a student. It includes 6 problems solved by the student using concepts like lists, loops, functions, conditional statements etc. For each problem, it provides the aim, algorithm, program code, output and result. The problems cover printing squares of list elements, calculating sum of first 5 natural numbers, generating tables, guessing game, pattern generation and conditional execution.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Python Exp 1

The document contains details of a Python programming assignment submitted by a student. It includes 6 problems solved by the student using concepts like lists, loops, functions, conditional statements etc. For each problem, it provides the aim, algorithm, program code, output and result. The problems cover printing squares of list elements, calculating sum of first 5 natural numbers, generating tables, guessing game, pattern generation and conditional execution.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Register No: URK21CS7046

Name: M. KARTHIK

Course code: 20CS1002L

Course name: Python Programming

Ex. No:01 Use of control statements

1. Program to print squares of all numbers present in a list

Aim:

To print squares of all numbers, present in a list.

Algorithm:

Step 1: Start the program.

Step 2: Declare the list and assign a variable to it.

Step 3: Use for loop and declare the condition.

Step 4: Display the output.

Step 5: Stop the program.

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:

To print the sum of the first 5 natural numbers.

Algorithm:

Step 1: Start the program.

Step 2: Declare the variable i =range (1,6)

Step 3: Declare the variable sum=0.

Step 4: Using for loop declare add each time the number to the sum.

Step 5: Display the output.

Step 6: Stop the program.

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:

To print table of given number using for loops.

Algorithm:

Step 1: Start the program.

Step 2: Get the input from the user and assign it to a variable name table.

Step 3: Use for loop and declare the condition.

Step 4: Display the output.

Step 5: Stop the program.

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:

To print table of given number using for loops.

Algorithm:

Step 1: Start the program.

Step 2: Get the input from the user and assign it to a variable name guess.

Step 3: Import random

Step 4: Use while loop and use If / else condition and specify the conditions to it.

Step 5: Display the output.

Step 6: Stop the program.

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:

To print table of given number using for loops.

Algorithm:

Step 1: Start the program.

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.

Step 5: Display the output.

Step 6: Stop the program.


Program:

a)

b)

Output:

a)
b)

Result:

The program is successfully executed and specific symbol is displayed as output.


6. Perform the following conditional actions:

a) If N is odd, print Weird

If N is even and in between 5 to 11, print Not Weird

If N is even and in between 13 to 35 , print Weird

If N is even and greater than 36, print Not Weird

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

both three and five print &’Karunya university’.

Aim:

To print table of given number using for loops.

Algorithm:

Step 1: Start the program.

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:

The program is successfully executed and the output is displayed.

You might also like