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

Core Python Assignment Task1 1GA22EC022

The document outlines a beginner-level Python assignment consisting of ten tasks, each demonstrating fundamental programming concepts. Tasks include checking if a number is even or odd, determining if a number is positive, negative, or zero, finding the largest of three numbers, displaying grades based on marks, printing numbers from 1 to N, calculating factorials, generating multiplication tables, reversing numbers, counting vowels in strings, and finding the largest and smallest elements in a list. Each task includes sample code and expected output.

Uploaded by

attom997.799
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)
12 views3 pages

Core Python Assignment Task1 1GA22EC022

The document outlines a beginner-level Python assignment consisting of ten tasks, each demonstrating fundamental programming concepts. Tasks include checking if a number is even or odd, determining if a number is positive, negative, or zero, finding the largest of three numbers, displaying grades based on marks, printing numbers from 1 to N, calculating factorials, generating multiplication tables, reversing numbers, counting vowels in strings, and finding the largest and smallest elements in a list. Each task includes sample code and expected output.

Uploaded by

attom997.799
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

CORE PYTHON ASSIGNMENT – BEGINNER LEVEL

Assignment: Task 1
Student USN: 1GA22EC022

Task 1: Check whether a number is Even or Odd


Code:
num = int(input("Enter a number: "))

if num % 2 == 0:
print("The number is Even")
else:
print("The number is Odd")
Sample Output:
Enter a number: 7
The number is Odd

Task 2: Check whether a number is Positive, Negative or Zero


Code:
num = int(input("Enter a number: "))

if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")
Sample Output:
Enter a number: -5
Negative number

Task 3: Find the Largest of Three Numbers


Code:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a >= b and a >= c:


print("Largest number is:", a)
elif b >= a and b >= c:
print("Largest number is:", b)
else:
print("Largest number is:", c)
Sample Output:
Largest number is: 45

Task 4: Display Grade Based on Marks


Code:
marks = int(input("Enter marks: "))

if marks >= 90:


print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 60:
print("Grade C")
elif marks >= 40:
print("Grade D")
else:
print("Fail")
Sample Output:
Grade B

Task 5: Print Numbers from 1 to N


Code:
n = int(input("Enter the value of N: "))

for i in range(1, n + 1):


print(i)
Sample Output:
1
2
3
4
5

Task 6: Calculate Factorial of a Number


Code:
num = int(input("Enter a number: "))
fact = 1

for i in range(1, num + 1):


fact = fact * i

print("Factorial is:", fact)


Sample Output:
Factorial is: 120

Task 7: Generate Multiplication Table


Code:
num = int(input("Enter a number: "))

for i in range(1, 11):


print(num, "x", i, "=", num * i)
Sample Output:
3 x 1 = 3
...
3 x 10 = 30

Task 8: Reverse a Number


Code:
num = int(input("Enter a number: "))
reverse = 0

while num > 0:


digit = num % 10
reverse = reverse * 10 + digit
num = num // 10

print("Reversed number:", reverse)


Sample Output:
Reversed number: 4321
Task 9: Count Vowels in a String
Code:
string = input("Enter a string: ")
vowels = "aeiouAEIOU"
count = 0

for char in string:


if char in vowels:
count += 1

print("Number of vowels:", count)


Sample Output:
Number of vowels: 4

Task 10: Find Largest and Smallest Elements in a List


Code:
numbers = list(map(int, input("Enter list elements: ").split()))

largest = numbers[0]
smallest = numbers[0]

for num in numbers:


if num > largest:
largest = num
if num < smallest:
smallest = num

print("Largest element:", largest)


print("Smallest element:", smallest)
Sample Output:
Largest element: 89
Smallest element: 7

You might also like