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

Week 1

Uploaded by

Praveena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Week 1

Uploaded by

Praveena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

DATE: EXP NO: PAGE NO:

Aim:
To write a program to find those numbers which are divisible by 7 and multiple
of 5 ,between 1500 and 2900.
Program:
nl = []
for x in range(1500, 2901):
if (x % 7 == 0) and (x % 5 == 0):
nl.append(str(x))
print(','.join(nl))

Executed Output:
1505,1540,1575,1610,1645,1680,
1715,1750,1785,1820,1855,1890,
1925,1960,1995,2030,2065,2100
,2135,2170,2205,2240,2275,2310,
2345,2380,2415,2450,2485,2520,
2555,2590,2625,2660,2695,2730,
2765,2800,2835,2870

Result:
Hence the program to find numbers which are divisible by 7 and multiple of
5 ,between 1500 and 2900 was executed successfully.
DATE: EXP NO: PAGE NO:

Aim:
To write a program to guess a number between 1 and 9.
Note: The user is prompted to enter a guess. If the user guesses incorrectly,
the prompt appears again until the guess is correct. Upon a successful guess,
the user will receive a "well guessed!" message, and the program will exit
Program:
from random import randint as rt
g= rt(1,9)

while True:
ug = int(input("Guess a number: "))
if g==ug:
print("Well guessed!")
break
else:
print("Incorrect!\n")

Executed Output:
Guess a number: 4
Incorrect!
Guess a number: 5
Incorrect!
Guess a number: 2
Incorrect!
Guess a number: 6
Incorrect!
DATE: EXP NO: PAGE NO:

Guess a number: 8
Incorrect!
Guess a number: 9
Well guessed!

Result:
Hence the program to swap two numbers without using a temporary variable
was executed successfully.

Aim:
To Write a Python program to construct the following pattern, using a nested
for loop.
DATE: EXP NO: PAGE NO:

Program:
a)
rows = 5
for i in range(rows, 0, -1):
for j in range(1, i + 1):
print(j, end=' ')
print("\r")
output:
12345
1234
123
12
1
b)
n = int(input("Enter the number of rows: "))
for i in range(1, n+1):
for j in range(1, i+1):
print(j, end=" ")
print()
output:
Enter the number of rows: 5
1
DATE: EXP NO: PAGE NO:

12
123
1234
12345
c)
rows = 3
k = 2 * rows - 2
for i in range(0, rows):
for j in range(0, k):
print(end=" ")
k=k-1
for j in range(0, i + 1):
print("* ", end="")
print("")
k = rows - 2
for i in range(rows, -1, -1):
for j in range(k, 0, -1):
print(end=" ")
k=k+1
for j in range(0, i + 1):
print("* ", end="")
print("")

output:
*
**
DATE: EXP NO: PAGE NO:

***
****
***
**
*

Result:
Hence the program to construct the given pattern using nested for loop was
executed successfully.

Aim:
To write a python program to cound the number of even and odd numbers
Sample numbers:numbers=(1,2,3,4,5,6,7,8,9)
DATE: EXP NO: PAGE NO:

Program:
def count_even_odd(numbers):
even_count = 0
odd_count = 0
for num in numbers:
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
return even_count, odd_count
# Test the function
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, ]
even_count, odd_count = count_even_odd(numbers)
print("Even numbers:", even_count)
print("Odd numbers:", odd_count)
Expected Output:
Even numbers: 4
Odd numbers: 5
Result:
Hence the program to cound the number of even and odd numbers was
executed successfully.

You might also like