Usman
Usman
Computer Programing
lab(1009)
Lab Title
Objective:
Tools/Software Requirement:
Python 3 Anaconda
Theoretical Explanation:
1. if Statement:
The if statement is used when you want to make a decision. It checks if a certain condition is true
or not. If the condition is true, the block of code inside the if statement gets executed.
2. if-else Statement:
An if-else statement is like a choice between two options. If the condition is true, the if part is
executed; if it’s false, the else part is executed.
3. Nested if-else:
A nested if-else is when you place an if-else statement inside another if or else statement. It’s
useful when you want to check multiple conditions step by step.
Lab Tasks:
Task #1:
Your university registration number shows the year of your intake. For example, in the
enrolment 201918 the first two numbers show your intake i.e. 20. Write a python
program which takes enrolment as an input and finds in which year you are enrolled ?
Code :
Input:
Task #2:
Write a python program to find the largest number among the three user input numbers.
Code:
1. print(' M Usman')
2. n1=int(input("enter first number :"))
3. n2=int(input("enter second number :"))
4. n3=int(input("enter third number :"))
5. if n1>n2 and n1>n3: print("number 1 is greater number ")
6. else: print("number 3 is greater number ")
Input:
phyton code to find the biggest number 1
Output:
Task #3:
Code:
if number%3==0:
else:
Input:
phyton code to find the even and odd num 1
Output:
Task#4:
Code:
1. print("M usman")
2. int1=int(input("enter a number"))
3. if int1>1
4. for i in range(2,(int1//2)+1):
5. if int1%i==0:
6. print("its a prime number")
7. break
8. else:
9. print('its a prime number')
10. break
11. else:
12. print('its not a brime number')
Input:
phyton code to find prime number 1
Output:
Input:
Output:
Task #2:
Input:
Output:
Task #3:
Input:
Output:
Task #4:
Input:
Output:
Task #5:
Input:
Output:
Task #6:
Input :
Output:
:Conclusion:
In this lab we learned about if-else statements and also about
nested statements . it gave us idea about the would a phyton
code would perform under certain conditions and certain
scenarios more over its engage me epically in phyton programing
and let me understood many problem solving strategies.