0% found this document useful (0 votes)
5 views2 pages

Python

The document contains five Python code snippets for basic programming tasks. These tasks include finding the largest of three numbers, calculating the sum of numbers from 1 to 100, determining if a number is positive, negative, or zero, computing the sum and average of user-entered numbers, and grading a student based on their marks. Each snippet demonstrates fundamental programming concepts such as input handling, conditionals, loops, and arithmetic operations.

Uploaded by

shreya
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)
5 views2 pages

Python

The document contains five Python code snippets for basic programming tasks. These tasks include finding the largest of three numbers, calculating the sum of numbers from 1 to 100, determining if a number is positive, negative, or zero, computing the sum and average of user-entered numbers, and grading a student based on their marks. Each snippet demonstrates fundamental programming concepts such as input handling, conditionals, loops, and arithmetic operations.

Uploaded by

shreya
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
You are on page 1/ 2

1) Find the largest of three numbers:

a=input('enter the first number: ')


b=input('enter the second number: ')
c=input('enter the third number: ')

if(a>b and a>c):


​ print('a is the largest')
if(b>c and b>a):
​ print('b is the largest')
if(c>b and c>a):
​ print('c is the largest')

2)Calculate the sum of numbers from 1 to 100:

sum = 0
i=1
while i <= 100:
sum += i
i += 1
print(sum)

3) Print if number is positive, negative or zero


num = 0
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

4)Find the sum and avg of numbers entered by user


n = int(input("How many numbers? : "))
sum = 0
for i in range(0, n):
num = float(input("Enter number: "))
sum += num

avg = sum/n

print("Average =", avg)


5)Grade a student based on marks:
marks =int(input(“enter marks”))
if(marks > 90):
print("Excellent")
elif(marks > 70):
print("Very Good")
elif(marks >= 50):
print("Good")
else:
print("Fail")

You might also like