0% found this document useful (0 votes)
19 views6 pages

Wa0010.

The document contains a series of Python programming exercises including finding the largest of three numbers, checking for leap years, generating number and star patterns, implementing FizzBuzz, calculating the sum of prime numbers, generating Fibonacci sequences, and creating complex patterns. Each question is accompanied by code snippets demonstrating the solution. The exercises cover basic programming concepts and loops.
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)
19 views6 pages

Wa0010.

The document contains a series of Python programming exercises including finding the largest of three numbers, checking for leap years, generating number and star patterns, implementing FizzBuzz, calculating the sum of prime numbers, generating Fibonacci sequences, and creating complex patterns. Each question is accompanied by code snippets demonstrating the solution. The exercises cover basic programming concepts and loops.
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/ 6

Question 1: Largest among three numbers

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)

Question 2: Check for leap year

Year = int(input(“Enter a year: “))

If (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):

Print(“Leap year”)

Else:

Print(“Not a leap year”)


Question 3: Pattern – Numbers

22

333

4444

55555

For I in range(1, 6):

Print(str(i) * i)

Question 4: Pattern – Stars

**

For I in range(1, 6):

Print(“*” * i)
Question 5 (both screenshots): Left-aligned triangle

**

For I in range(1, 5):

Print(“*” * i)

Question 6: FizzBuzz

For I in range(1, 101):

If I % 3 == 0 and I % 5 == 0:

Print(“FizzBuzz”)

Elif I % 3 == 0:

Print(“Fizz”)

Elif I % 5 == 0:

Print(“Buzz”)

Else:

Print(i)
Question 7: Sum of prime numbers up to n

Def is_prime(num):

If num < 2:

Return False

For I in range(2, int(num**0.5) + 1):

If num % I == 0:

Return False

Return True

N = int(input(“Enter a number: “))

Sum_primes = sum(I for I in range(n + 1) if is_prime(i))

Print(“Sum of prime numbers:”, sum_primes)

Question 8: Fibonacci sequence up to n terms

N = int(input(“Enter number of terms: “))

A, b = 0, 1

For _ in range(n):

Print(a, end=” “)

A, b = b, a + b
Question 9: Complex pattern

For I in range(1, 5):

Print(“*” * (I * i))

Question 10: Alphabet pattern

BBB

CCCCC

DDDDDDD

EEEEEEEEE

For I in range(5):

Ch = chr(65 + i) # 65 is ASCII for ‘A’

Print(ch * (2 * I + 1))

You might also like