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

Code Programs for Inter

The document contains various Python code programs for inter-school activities, including a word count program, Fibonacci number generator, calculator, random number guessing game, prime number checker, multiplication table generator, and palindrome checker. Each program demonstrates basic programming concepts and user input handling. The code snippets are intended for educational purposes to help students learn Python programming.

Uploaded by

eshanmohammed71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Code Programs for Inter

The document contains various Python code programs for inter-school activities, including a word count program, Fibonacci number generator, calculator, random number guessing game, prime number checker, multiplication table generator, and palindrome checker. Each program demonstrates basic programming concepts and user input handling. The code snippets are intended for educational purposes to help students learn Python programming.

Uploaded by

eshanmohammed71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Code Programs for Inter-school

#Word Count: shows the number of words


sentence= "THIS IS AN EXAMPLE"
print(sentence.split())
print(len(sentence.split()))

#Fabinacci:
# Function to generate Fibonacci numbers
def fibonacci(n):
a, b = 0, 1
result = []
for i in range(n):
result.append(a)
a, b = b, a + b
return result

# Example usage
n = 10
print(f"The first {n} Fibonacci numbers are: {fibonacci(n)}")

#Calculator
operator=(input("Enter a method (+ - * /):"))
num1=float(input("Enter first number"))
num2=float(input("Enter second number"))

if operator=='+':
result=(num1+num2)
print(result)
elif operator=='-':
result=(num1-num2)
print(result)
elif operator=='*':
result=(num1*num2)
print(result)
elif operator=='/':
result=(num1/num2)
print(result)

#Random Guessing
import random

lowest_num=1
highest_num=100
answer=random.randint(lowest_num,highest_num)
guess=0
is_running=True
print("welcome to python number guessing game")
print(f"select a number between{lowest_number} and {highest-
number}")

while is_running:
guess= input("Enter your guess:")
if guess.isdigit():
guess=int (guess)
guess+=1

if guess < lowest_number or guess > highest_number:


print("Guess is invalid try again")
print(f"Please select a number between {lowest_num} and
{highest_num}")

elif guess<answer:
print("too low ! try again")
elif guess>answer:
print("too high! try again")
else:print("correct!"f"the answer was{answer}")
is_running=False

#Prime numbers
num = 407

# To take input from the user


#num = int(input("Enter a number: "))
if num == 0 or num == 1:
print(num, "is not a prime number")
elif num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")

# if input number is less than


# or equal to 1, it is not prime
else:
print(num,"is not a prime number")

# Multiplication table (from 1 to 10) in Python

num = 12

# To take input from the user


# num = int(input("Display multiplication table of? "))
# Iterate 10 times from i = 1 to 10
for i in range(1, 11):
print(num, 'x', i, '=', num*i)

#Palindrome
s= input("enter the value")
reverse=[::-1]
if (s== reverse):
print("yes it is a plaindrome")
else:
PRINT("NO IT ISNT")

You might also like