0% found this document useful (0 votes)
6 views3 pages

Week2 Code Output

The document contains Python code snippets for various programming tasks, including counting even and odd numbers, filtering words that start with a vowel, recording student marks, counting divisibility by 3, checking for prime numbers, and counting character types in a string. Each task includes a main function that prompts user input and displays the results. The code is structured to be run in a Jupyter notebook environment.

Uploaded by

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

Week2 Code Output

The document contains Python code snippets for various programming tasks, including counting even and odd numbers, filtering words that start with a vowel, recording student marks, counting divisibility by 3, checking for prime numbers, and counting character types in a string. Each task includes a main function that prompts user input and displays the results. The code is structured to be run in a Jupyter notebook environment.

Uploaded by

bhavya3960
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2/25/26, 12:17 AM week2.

ipynb - Colab

keyboard_arrow_down Q1

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 {"Odd:":odd_count, "Even:":even_count}

def main():

numbers = []
n = int(input("Enter how many numbers you want to store in your list: "))

for i in range(n):
num = int(input(f"Enter Number {i+1}: "))
[Link](num)

result = count_even_odd(numbers)
print(result)

if __name__ == "__main__":
main()

Enter how many numbers you want to store in your list: 4


Enter Number 1: 34
Enter Number 2: 56
Enter Number 3: 99
Enter Number 4: 12
{'Odd:': 1, 'Even:': 3}

keyboard_arrow_down Q2

def starts_with_vowel(list1):
list2 = []
for word in list1:
if word[0].lower().startswith(('a','i','o','e','u')):
[Link](word)

return list2

list1 = []
n = int(input("Enter how many words you want to add to list: "))
for i in range(n):
word = input(f"Enter word {i+1}: ")
[Link](word)

result = starts_with_vowel(list1)
print(f"Words that starts with a vowel: {result}")

Enter how many words you want to add to list: 3


Enter word 1: opus
Enter word 2: gray
Enter word 3: tree
Words that starts with a vowel: ['opus']

keyboard_arrow_down Q3

def main():
students = {}

n = int(input("Enter How many Student data enteries you want: "))

for i in range(n):
[Link] 1/4
2/25/26, 12:17 AM [Link] - Colab
name = input(f"Enter Name of Student {i+1}: ")
Marks = float(input(f"Enter Marks of Student {i+1}: "))
students[name] = Marks

print("Student who got marks more than 75: ")


for name,Marks in [Link]():
if Marks > 75:
print(name)

if __name__ == "__main__":
main()

Enter How many Student data enteries you want: 3


Enter Name of Student 1: Bhavya
Enter Marks of Student 1: 88
Enter Name of Student 2: Anargh
Enter Marks of Student 2: 74
Enter Name of Student 3: Pragati
Enter Marks of Student 3: 93
Student who got marks more than 75:
Bhavya
Pragati

keyboard_arrow_down Q4

def count_divisibilty(numbers):
tuple2 = ()
for num in numbers:
if num % 3 == 0:
tuple2 = tuple2 + (num,)
return tuple2

def main():

numbers = ()
n = int(input("Enter how many numbers you want to store in your tuple: "))

for i in range(n):
num = int(input(f"Enter Number {i+1}: "))
numbers = numbers + (num,)

result = count_divisibilty(numbers)
print(result)

if __name__ == "__main__":
main()

Enter how many numbers you want to store in your tuple: 4


Enter Number 1: 8
Enter Number 2: 3
Enter Number 3: 2
Enter Number 4: 1
(3,)

keyboard_arrow_down Q5

def is_prime(num):
if num <= 1:
return False

for i in range(2, int(num**0.5) + 1):


if num % i == 0:
return False
return True

def prime_number_check(numbers):
prime_list = []

for num in numbers:


if is_prime(num):
prime_list.append(num)

[Link] 2/4
2/25/26, 12:17 AM [Link] - Colab
return prime_list

def main():
numbers = []
n = int(input("Enter how many numbers you want to store in your list: "))

for i in range(n):
num = int(input(f"Enter Number {i+1}: "))
[Link](num)

result = prime_number_check(numbers)
print("Prime numbers:", result)

if __name__ == "__main__":
main()

Enter how many numbers you want to store in your list: 3


Enter Number 1: 56
Enter Number 2: 71
Enter Number 3: 48
Prime numbers: [71]

keyboard_arrow_down Q6

def count_characters(text):
result = {
"Uppercase": 0,
"Lowercase": 0,
"Digits": 0
}

for ch in text:
if [Link]():
result["Uppercase"] += 1
elif [Link]():
result["Lowercase"] += 1
elif [Link]():
result["Digits"] += 1

return result

def main():
text = input("Enter a string: ")
counts = count_characters(text)
print(counts)

if __name__ == "__main__":
main()

Enter a string: bhAVya0309


{'Uppercase': 2, 'Lowercase': 4, 'Digits': 4}

[Link] 3/4

You might also like