0% found this document useful (0 votes)
3 views

Python_Tasks_Monospaced

The document contains a series of Python programs that cover various topics including population growth, prime number generation, a number guessing game, and mathematical computations such as GCD and sums of specific integers. Each section includes code snippets that demonstrate the functionality of the respective program. The programs are interactive, requiring user input for certain calculations.

Uploaded by

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

Python_Tasks_Monospaced

The document contains a series of Python programs that cover various topics including population growth, prime number generation, a number guessing game, and mathematical computations such as GCD and sums of specific integers. Each section includes code snippets that demonstrate the functionality of the respective program. The programs are interactive, requiring user input for certain calculations.

Uploaded by

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

# 1.

Population growth over the last decade

print("1. Population Growth Over the Last Decade")

population = 100000

for year in range(1, 11):

population *= 1.10

print(f"Year {year}: Population = {int(population)}")

# 2. Alternate prime numbers till 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

print("\n2. Alternate Prime Numbers Till N")

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

alt_primes = [num for num in range(2, N + 1) if is_prime(num)][::2]

print("Alternate prime numbers:", alt_primes)

# 3. Number guessing game

print("\n3. Number Guessing Game")

import random

correct_number = random.randint(1, 100)

attempts = 5
print("Guess a number between 1 and 100. You have 5 attempts.")

while attempts > 0:

guess = int(input("Your guess: "))

if guess == correct_number:

print("Congratulations! You guessed the correct number.")

break

elif guess < correct_number:

print("Hint: Guess higher!")

else:

print("Hint: Guess lower!")

attempts -= 1

if attempts == 0:

print(f"Sorry! The correct number was {correct_number}.")

# 4. Sum of integers divisible by 6 but not by 4 below a limit

print("\n4. Sum of Integers Divisible by 6 but Not by 4")

upper_limit = int(input("Enter the upper limit: "))

result_sum = sum(i for i in range(1, upper_limit) if i % 6 == 0 and i % 4 != 0)

print(f"Sum = {result_sum}")

# 5. Sum of digits that are prime

print("\n5. Sum of Digits That Are Prime")

upper_limit = int(input("Enter the upper limit: "))

for number in range(1, upper_limit + 1):

digit_sum = sum(int(digit) for digit in str(number))


if is_prime(digit_sum):

print(f"Number: {number}, Sum of digits: {digit_sum}")

# 6. Palindromic number check

print("\n6. Palindromic Number Check")

number = input("Enter a number: ")

if number == number[::-1]:

print(f"{number} is a palindromic number.")

else:

print(f"{number} is not a palindromic number.")

# 7. Reverse a three-digit number

print("\n7. Reverse a Three-Digit Number")

number = input("Enter a three-digit number: ")

if len(number) == 3:

print(f"Reversed number: {number[::-1]}")

else:

print("Please enter a valid three-digit number.")

# 8. GCD of two numbers

print("\n8. GCD of Two Numbers")

def gcd(a, b):

while b:

a, b = b, a % b

return a

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


num2 = int(input("Enter the second number: "))

print(f"GCD of {num1} and {num2} is {gcd(num1, num2)}.")

You might also like