SlideShare a Scribd company logo
week2
1)Aim: Print the below triangle using for loop.
rows = 6
for i in range(rows):
for j in range(i):
print(i, end=' ')
print('')
output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
2)Aim:Write a program to check whether the given input is digit or lowercase
character or uppercase character or a special character (use 'if-else-if' ladder).
ch = input("Please Enter Your Own Character : ")
if(ch >= 'A' and ch <= 'Z'):
print("The Given Character ", ch, "is an Uppercase Alphabet")
elif(ch >= 'a' and ch <= 'z'):
print("The Given Character ", ch, "is a Lowercase Alphabet")
else:
print("The Given Character ", ch, "is Not a Lower or Uppercase Alphabet")
output
Please Enter Your Own Character : a
The Given Character a is a Lowercase Alphabet
Please Enter Your Own Character : 1
The Given Character 1 is Not a Lower or Uppercase Alphabet
Please Enter Your Own Character : A
The Given Character A is an Uppercase Alphabet
3)Aim:Python Program to Print the Fibonacci sequence
using while loop.
# Taking the number of terms to be printed as input
n = int(input("Enter the number of terms: "))
# Initializing the first two terms of the sequence
a, b = 0, 1
# Loop to print the Fibonacci sequence
while a < n:
print(a, end=" ")
a, b = b, a+b
Aim:Python Program to Print the Fibonacci sequence using while loop.
n = int(input("Enter the
number of terms: "))
a, b = 0, 1
while a < n:
print(a, end=" ")
a, b = b, a+b
output
Enter the number of terms: 15
0 1 1 2 3 5 8 13
4)Aim:Python program to print all prime numbers
in a given interval (usebreak).
lower = int(input("Enter lower bound: ")) # User inputs lower bound
upper = int(input("Enter upper bound: ")) # User inputs upper bound
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1): # Loop through numbers in the given
range
if num > 1: # Prime numbers are greater than 1
for i in range(2, num): # Check divisibility from 2 to num-1
if (num % i) == 0: # If num is divisible, it's not prime
break # Exit loop early if a divisor is found
else:
print(num) # If no divisors are found, num is prime
lower = int(input("Enter lower bound: "))
upper = int(input("Enter upper bound: "))
print("Prime numbers between", lower, "and",
upper, "are:")
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num):
if(num % i) == 0:
break
else:
print(num)
output
Enter lower bound: 1
Enter upper bound: 22
Prime numbers between 1 and 22 are:
2
3
5
7
11
13
17
19

More Related Content

PDF
Sasin nisar
PPTX
Mastering Python lesson 3a
PPTX
Loops in Python
DOCX
CBSE Class 12 Computer practical Python Programs and MYSQL
PDF
Sample Program file class 11.pdf
PDF
cos 102 - getting into programming with python.pdf
PDF
Python programs
PPTX
Practice_Exercises_Control_Flow.pptx
Sasin nisar
Mastering Python lesson 3a
Loops in Python
CBSE Class 12 Computer practical Python Programs and MYSQL
Sample Program file class 11.pdf
cos 102 - getting into programming with python.pdf
Python programs
Practice_Exercises_Control_Flow.pptx

Similar to week2.pptx program program program problems (20)

PPTX
Chapter 9 Conditional and Iterative Statements.pptx
PDF
xii cs practicals
PPTX
Unit 8.4Testing condition _ Developing Games.pptx
PDF
Introduction to phyton , important topic
PDF
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
PDF
datastructure-1 lab manual journals practical
PPTX
Looping in PythonLab8 lecture slides.pptx
PPTX
Course work Questions and answers .pptx
PDF
python practicals-solution-2019-20-class-xii.pdf
PPTX
1. control structures in the python.pptx
PDF
gdscpython.pdf
PDF
xii cs practicals class 12 computer science.pdf
PDF
GE3151_PSPP_UNIT_3_Notes
PDF
02 Control Structures - Loops & Conditions
PPTX
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
PDF
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
PPTX
ANSHUL RANA - PROGRAM FILE.pptx
PPTX
Chapter 9 Conditional and Iterative Statements.pptx
PDF
Recitation2IntroductionToPython.pptx.pdf
PDF
Python programming Workshop SITTTR - Kalamassery
Chapter 9 Conditional and Iterative Statements.pptx
xii cs practicals
Unit 8.4Testing condition _ Developing Games.pptx
Introduction to phyton , important topic
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
datastructure-1 lab manual journals practical
Looping in PythonLab8 lecture slides.pptx
Course work Questions and answers .pptx
python practicals-solution-2019-20-class-xii.pdf
1. control structures in the python.pptx
gdscpython.pdf
xii cs practicals class 12 computer science.pdf
GE3151_PSPP_UNIT_3_Notes
02 Control Structures - Loops & Conditions
module 3 BTECH FIRST YEAR ATP APJ KTU PYTHON
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
ANSHUL RANA - PROGRAM FILE.pptx
Chapter 9 Conditional and Iterative Statements.pptx
Recitation2IntroductionToPython.pptx.pdf
Python programming Workshop SITTTR - Kalamassery
Ad

Recently uploaded (20)

PPTX
mahatma gandhi bus terminal in india Case Study.pptx
PPTX
12. Community Pharmacy and How to organize it
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PPTX
6- Architecture design complete (1).pptx
PDF
Benefits_of_Cast_Aluminium_Doors_Presentation.pdf
PPTX
areprosthodontics and orthodonticsa text.pptx
PPTX
artificialintelligencedata driven analytics23.pptx
PPTX
503ea471-f798-4324-90e8-275bdab41942.pptx
PPTX
Fundamental Principles of Visual Graphic Design.pptx
PDF
Shape Language for Character Design by Adhec Saputra
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PDF
Applied Structural and Petroleum Geology Lec 1.pdf
PPT
Machine printing techniques and plangi dyeing
PPTX
Implications Existing phase plan and its feasibility.pptx
PDF
AUB Collaborative Book Project - Keiko Toyoda
PDF
The Advantages of Working With a Design-Build Studio
PPT
Package Design Design Kit 20100009 PWM IC by Bee Technologies
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PPTX
AD Bungalow Case studies Sem 2.pptxvwewev
PDF
MARIJA CVITKOVAC - GRAPHIC DESIGN PORTFOLIO 2025
mahatma gandhi bus terminal in india Case Study.pptx
12. Community Pharmacy and How to organize it
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
6- Architecture design complete (1).pptx
Benefits_of_Cast_Aluminium_Doors_Presentation.pdf
areprosthodontics and orthodonticsa text.pptx
artificialintelligencedata driven analytics23.pptx
503ea471-f798-4324-90e8-275bdab41942.pptx
Fundamental Principles of Visual Graphic Design.pptx
Shape Language for Character Design by Adhec Saputra
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
Applied Structural and Petroleum Geology Lec 1.pdf
Machine printing techniques and plangi dyeing
Implications Existing phase plan and its feasibility.pptx
AUB Collaborative Book Project - Keiko Toyoda
The Advantages of Working With a Design-Build Studio
Package Design Design Kit 20100009 PWM IC by Bee Technologies
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
AD Bungalow Case studies Sem 2.pptxvwewev
MARIJA CVITKOVAC - GRAPHIC DESIGN PORTFOLIO 2025
Ad

week2.pptx program program program problems

  • 2. 1)Aim: Print the below triangle using for loop. rows = 6 for i in range(rows): for j in range(i): print(i, end=' ') print('')
  • 3. output 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
  • 4. 2)Aim:Write a program to check whether the given input is digit or lowercase character or uppercase character or a special character (use 'if-else-if' ladder). ch = input("Please Enter Your Own Character : ") if(ch >= 'A' and ch <= 'Z'): print("The Given Character ", ch, "is an Uppercase Alphabet") elif(ch >= 'a' and ch <= 'z'): print("The Given Character ", ch, "is a Lowercase Alphabet") else: print("The Given Character ", ch, "is Not a Lower or Uppercase Alphabet")
  • 5. output Please Enter Your Own Character : a The Given Character a is a Lowercase Alphabet Please Enter Your Own Character : 1 The Given Character 1 is Not a Lower or Uppercase Alphabet Please Enter Your Own Character : A The Given Character A is an Uppercase Alphabet
  • 6. 3)Aim:Python Program to Print the Fibonacci sequence using while loop. # Taking the number of terms to be printed as input n = int(input("Enter the number of terms: ")) # Initializing the first two terms of the sequence a, b = 0, 1 # Loop to print the Fibonacci sequence while a < n: print(a, end=" ") a, b = b, a+b
  • 7. Aim:Python Program to Print the Fibonacci sequence using while loop. n = int(input("Enter the number of terms: ")) a, b = 0, 1 while a < n: print(a, end=" ") a, b = b, a+b output Enter the number of terms: 15 0 1 1 2 3 5 8 13
  • 8. 4)Aim:Python program to print all prime numbers in a given interval (usebreak). lower = int(input("Enter lower bound: ")) # User inputs lower bound upper = int(input("Enter upper bound: ")) # User inputs upper bound print("Prime numbers between", lower, "and", upper, "are:") for num in range(lower, upper + 1): # Loop through numbers in the given range if num > 1: # Prime numbers are greater than 1 for i in range(2, num): # Check divisibility from 2 to num-1 if (num % i) == 0: # If num is divisible, it's not prime break # Exit loop early if a divisor is found else: print(num) # If no divisors are found, num is prime
  • 9. lower = int(input("Enter lower bound: ")) upper = int(input("Enter upper bound: ")) print("Prime numbers between", lower, "and", upper, "are:") for num in range(lower, upper + 1): if num > 1: for i in range(2, num): if(num % i) == 0: break else: print(num)
  • 10. output Enter lower bound: 1 Enter upper bound: 22 Prime numbers between 1 and 22 are: 2 3 5 7 11 13 17 19