SlideShare a Scribd company logo
NAME: MOHSIN ALVI
ID:14136
Lab-04
Loops in python
Objectives:
The purpose of this lab is to get you familiar with the loops (for, while) and loop
controlling statements in Python
Exercises
1. Write a program that prints your name 100 times.
2. Write a program to fill the screen horizontally and vertically with your name. [Hint: add
the option end='' into the print function to fill the screen horizontally.]
3. Write a program that outputs 100 lines, numbered 1 to 100, each with your name on it. The
output should look like the output below.
1 Your name
2 Your name
3 Your name
4 Your name
...
100 Your name
4. Write a program that prints out a list of the integers from 1 to 20 and their squares. The
output should look like this:
1 --- 1
2 --- 4
3 --- 9
...
20 --- 400
5. Write a program that uses a for loop to print the numbers 8, 11, 14, 17, 20, . . . , 83, 86, 89.
6. Write a program that uses a for loop to print the numbers 100, 98, 96, . . . , 4, 2.
7. Write a program that uses exactly four for loops to print the sequence of letters below.
AAAAAAAAAABBBBBBBCDCDCDCDEFFFFFFG
8. Write a program that asks the user for their name and how many times to print it. The
program should print out the user’s name the specified number of times.
9. Use a for loop to print an upside down triangle like the one below. Allow the user to specify
how high the triangle should be.
10. The code below prints the numbers from 1 to 50. Rewrite the code using a while loop to
accomplish the same thing.
for i in range(1,51):
print(i)
11. Write a program that uses a while loop (not a for loop) to read through a string and print
the characters of the string one-by-one on separate lines.
12. Modify the program above to print out every second character of the string.
13. A good program will make sure that the data its users enter is valid. Write a program that
asks the user for a weight and converts it from kilograms to pounds. Whenever the user
enters a weight below 0, the program should tell them that their entry is invalid and then
ask them again to enter a weight. [Hint: Use a while loop, not an if statement].
Lab-05
Nested loops in Python
Objectives:
The purpose of this lab is to get you familiar with the concept of nested loops and
how we use them to designing different patterns in Python.
Exercises
1. Print a rectangle Pattern with 5 rows and 3 columns of stars
2. Write a program that allows the user to try guessing a password. It should allow them to
guess the password up to three times.
 You will need to use:
 At least one while loop
 String comparison
 Conditionals
 Decision Structures
3. Write a program that prints a giant letter A like the one below. Allow the user to specify
how large the letter should be.
4. Write a program that prints a starting letter of your name. Allow the user to specify how
large the letter should be.
Lab-06
Miscellaneous Topics I
Objectives:
The purpose of this lab is to get you familiar with some common techniques and
other useful information.
Exercises
1. Write a program that counts how many of the squares of the numbers from 1 to 100 end in
a 1.
2. Write a program that counts how many of the squares of the numbers from 1 to 100 end in
a 4 and how many end in a 9.
3. Write a program that asks the user to enter a number and prints the sum of the divisors of
that number. The sum of the divisors of a number is an important function in number
theory.
4. Ask the user to enter 10 test scores. Write a program to do the following:
i. Print out the highest and lowest scores.
ii. Print out the average of the scores.
iii. Print out the second largest score.
iv. If any of the scores is greater than 100, then after all the scores have been entered,
print a message warning the user that a value over 100 has been entered.
v. Drop the two lowest scores and print out the average of the rest of them.

More Related Content

PPTX
Introduction to Python Basics Programming
PPT
Time andspacecomplexity
PDF
Datatypes in Python.pdf
PPTX
Introduction to data structure
PDF
PPT
Algorithm And analysis Lecture 03& 04-time complexity.
PPTX
Algorithm Complexity and Main Concepts
PDF
Python ppt.pdf
Introduction to Python Basics Programming
Time andspacecomplexity
Datatypes in Python.pdf
Introduction to data structure
Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm Complexity and Main Concepts
Python ppt.pdf

What's hot (20)

PPTX
array of object pointer in c++
PPTX
Rule based system
PPT
Function overloading(c++)
PDF
Discrete Mathematics Lecture Notes
PDF
Python NumPy Tutorial | NumPy Array | Edureka
PPTX
Fuzzy arithmetic
PPTX
Machine Learning vs. Deep Learning
PDF
Python libraries
PPTX
11 Unit 1 Problem Solving Techniques
PPTX
NumPy.pptx
PPTX
Data types in python
PPTX
Performance analysis and randamized agoritham
PDF
PR 113: The Perception Distortion Tradeoff
PPTX
Ensemble methods in machine learning
PDF
Image analysis using python
PPTX
Bubble sort, Selection sort SORTING .pptx
PPTX
Evaluating hypothesis
PPTX
Space complexity
PPTX
Data Analysis in Python-NumPy
array of object pointer in c++
Rule based system
Function overloading(c++)
Discrete Mathematics Lecture Notes
Python NumPy Tutorial | NumPy Array | Edureka
Fuzzy arithmetic
Machine Learning vs. Deep Learning
Python libraries
11 Unit 1 Problem Solving Techniques
NumPy.pptx
Data types in python
Performance analysis and randamized agoritham
PR 113: The Perception Distortion Tradeoff
Ensemble methods in machine learning
Image analysis using python
Bubble sort, Selection sort SORTING .pptx
Evaluating hypothesis
Space complexity
Data Analysis in Python-NumPy
Ad

Similar to Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx (20)

PPTX
Looping in PythonLab8 lecture slides.pptx
PPTX
loops in Python with examples and different problems
PPTX
Practice_Exercises_Control_Flow.pptx
DOCX
Important C program of Balagurusamy Book
PPTX
Mastering Python lesson 3a
PDF
Sasin nisar
PDF
xii cs practicals
PDF
Python Lab Manual for First year Engineering students
DOCX
Python lab manual all the experiments are available
PPTX
Mastering Python lesson3b_for_loops
PPTX
ANSHUL RANA - PROGRAM FILE.pptx
PPTX
Python programming workshop session 2
DOCX
Oop lab assignment 01
PDF
Python_Module_2.pdf
PDF
PDF
PPTX
Chapter 9 Conditional and Iterative Statements.pptx
PPTX
Loops in Python
PDF
2 Python Basics II meeting 2 tunghai university pdf
Looping in PythonLab8 lecture slides.pptx
loops in Python with examples and different problems
Practice_Exercises_Control_Flow.pptx
Important C program of Balagurusamy Book
Mastering Python lesson 3a
Sasin nisar
xii cs practicals
Python Lab Manual for First year Engineering students
Python lab manual all the experiments are available
Mastering Python lesson3b_for_loops
ANSHUL RANA - PROGRAM FILE.pptx
Python programming workshop session 2
Oop lab assignment 01
Python_Module_2.pdf
Chapter 9 Conditional and Iterative Statements.pptx
Loops in Python
2 Python Basics II meeting 2 tunghai university pdf
Ad

Recently uploaded (20)

PPTX
Negotiation and Persuasion Skills: A Shrewd Person's Perspective
PDF
Digital Marketing & E-commerce Certificate Glossary.pdf.................
PPTX
basic introduction to research chapter 1.pptx
PDF
NEW - FEES STRUCTURES (01-july-2024).pdf
PDF
PMB 401-Identification-of-Potential-Biotechnological-Products.pdf
PDF
Daniels 2024 Inclusive, Sustainable Development
PPTX
BUSINESS CYCLE_INFLATION AND UNEMPLOYMENT.pptx
PPTX
interschool scomp.pptxzdkjhdjvdjvdjdhjhieij
PPTX
CTG - Business Update 2Q2025 & 6M2025.pptx
PPTX
operations management : demand supply ch
PDF
Cours de Système d'information about ERP.pdf
PDF
NewBase 12 August 2025 Energy News issue - 1812 by Khaled Al Awadi_compresse...
PDF
Booking.com The Global AI Sentiment Report 2025
PDF
Susan Semmelmann: Enriching the Lives of others through her Talents and Bless...
PPTX
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
DOCX
Handbook of Entrepreneurship- Chapter 5: Identifying business opportunity.docx
PPTX
TRAINNING, DEVELOPMENT AND APPRAISAL.pptx
PDF
ANALYZING THE OPPORTUNITIES OF DIGITAL MARKETING IN BANGLADESH TO PROVIDE AN ...
PPTX
Project Management_ SMART Projects Class.pptx
PDF
How to Get Business Funding for Small Business Fast
Negotiation and Persuasion Skills: A Shrewd Person's Perspective
Digital Marketing & E-commerce Certificate Glossary.pdf.................
basic introduction to research chapter 1.pptx
NEW - FEES STRUCTURES (01-july-2024).pdf
PMB 401-Identification-of-Potential-Biotechnological-Products.pdf
Daniels 2024 Inclusive, Sustainable Development
BUSINESS CYCLE_INFLATION AND UNEMPLOYMENT.pptx
interschool scomp.pptxzdkjhdjvdjvdjdhjhieij
CTG - Business Update 2Q2025 & 6M2025.pptx
operations management : demand supply ch
Cours de Système d'information about ERP.pdf
NewBase 12 August 2025 Energy News issue - 1812 by Khaled Al Awadi_compresse...
Booking.com The Global AI Sentiment Report 2025
Susan Semmelmann: Enriching the Lives of others through her Talents and Bless...
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
Handbook of Entrepreneurship- Chapter 5: Identifying business opportunity.docx
TRAINNING, DEVELOPMENT AND APPRAISAL.pptx
ANALYZING THE OPPORTUNITIES OF DIGITAL MARKETING IN BANGLADESH TO PROVIDE AN ...
Project Management_ SMART Projects Class.pptx
How to Get Business Funding for Small Business Fast

Lab 4 ,5 & 6 Submission (3) 14136_Mohsin Alvi.docx

  • 1. NAME: MOHSIN ALVI ID:14136 Lab-04 Loops in python Objectives: The purpose of this lab is to get you familiar with the loops (for, while) and loop controlling statements in Python Exercises 1. Write a program that prints your name 100 times. 2. Write a program to fill the screen horizontally and vertically with your name. [Hint: add the option end='' into the print function to fill the screen horizontally.]
  • 2. 3. Write a program that outputs 100 lines, numbered 1 to 100, each with your name on it. The output should look like the output below. 1 Your name 2 Your name 3 Your name 4 Your name ... 100 Your name
  • 3. 4. Write a program that prints out a list of the integers from 1 to 20 and their squares. The output should look like this: 1 --- 1 2 --- 4 3 --- 9 ... 20 --- 400
  • 4. 5. Write a program that uses a for loop to print the numbers 8, 11, 14, 17, 20, . . . , 83, 86, 89. 6. Write a program that uses a for loop to print the numbers 100, 98, 96, . . . , 4, 2. 7. Write a program that uses exactly four for loops to print the sequence of letters below. AAAAAAAAAABBBBBBBCDCDCDCDEFFFFFFG
  • 5. 8. Write a program that asks the user for their name and how many times to print it. The program should print out the user’s name the specified number of times. 9. Use a for loop to print an upside down triangle like the one below. Allow the user to specify how high the triangle should be. 10. The code below prints the numbers from 1 to 50. Rewrite the code using a while loop to accomplish the same thing. for i in range(1,51): print(i)
  • 6. 11. Write a program that uses a while loop (not a for loop) to read through a string and print the characters of the string one-by-one on separate lines.
  • 7. 12. Modify the program above to print out every second character of the string. 13. A good program will make sure that the data its users enter is valid. Write a program that asks the user for a weight and converts it from kilograms to pounds. Whenever the user enters a weight below 0, the program should tell them that their entry is invalid and then ask them again to enter a weight. [Hint: Use a while loop, not an if statement].
  • 8. Lab-05 Nested loops in Python Objectives: The purpose of this lab is to get you familiar with the concept of nested loops and how we use them to designing different patterns in Python.
  • 9. Exercises 1. Print a rectangle Pattern with 5 rows and 3 columns of stars 2. Write a program that allows the user to try guessing a password. It should allow them to guess the password up to three times.  You will need to use:  At least one while loop  String comparison  Conditionals  Decision Structures
  • 10. 3. Write a program that prints a giant letter A like the one below. Allow the user to specify how large the letter should be.
  • 11. 4. Write a program that prints a starting letter of your name. Allow the user to specify how large the letter should be. Lab-06 Miscellaneous Topics I Objectives: The purpose of this lab is to get you familiar with some common techniques and other useful information.
  • 12. Exercises 1. Write a program that counts how many of the squares of the numbers from 1 to 100 end in a 1. 2. Write a program that counts how many of the squares of the numbers from 1 to 100 end in a 4 and how many end in a 9. 3. Write a program that asks the user to enter a number and prints the sum of the divisors of that number. The sum of the divisors of a number is an important function in number theory.
  • 13. 4. Ask the user to enter 10 test scores. Write a program to do the following: i. Print out the highest and lowest scores. ii. Print out the average of the scores. iii. Print out the second largest score.
  • 14. iv. If any of the scores is greater than 100, then after all the scores have been entered, print a message warning the user that a value over 100 has been entered. v. Drop the two lowest scores and print out the average of the rest of them.