Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Python Programming Exercises For Edexcel

The document contains code snippets that demonstrate different ways to work with numbers in Python including: finding the largest of three numbers entered by the user, counting even and odd numbers in a list, printing the factors of a number, and determining if a number is prime.

Uploaded by

Nia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Python Programming Exercises For Edexcel

The document contains code snippets that demonstrate different ways to work with numbers in Python including: finding the largest of three numbers entered by the user, counting even and odd numbers in a list, printing the factors of a number, and determining if a number is prime.

Uploaded by

Nia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1)

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The largest number is", largest)

2)

list1 = [10, 21, 4, 45, 66, 93, 1]


even_count, odd_count = 0, 0

for num in list1:

if num % 2 == 0:

even_count += 1

else:

odd_count += 1

print("Even numbers in the list: ", even_count)

print("Odd numbers in the list: ", odd_count)


3)

def print_factors(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)

num = int(input("Enter the number: "))

print_factors(num)

4)

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

prime = False

if num > 1:
for i in range(2, num):
if (num % i) == 0:
prime = True
break

if prime:
print(num, "is not a prime number")
else:
print(num, "is a prime number")

You might also like