Unlocking Python's Potential: Exploring Fibonacci Series, Factorials, Prime Numbers, and Temperature Conversion
Here are a few more simple programs that you can try:
- Fibonacci Series This program generates and prints the Fibonacci series up to a specified number of terms.
pythonn = int(input("Enter the number of terms: "))
# Initialize the first two terms
a, b = 0, 1
print("Fibonacci Series:")
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
- Factorial Calculation This program calculates the factorial of a given number.
pythonn = int(input("Enter a number: "))
factorial = 1
for i in range(1, n + 1):
factorial *= i
print("The factorial of", n, "is", factorial)
- Prime Number Check This program checks whether a given number is prime or not.
pythonnum = int(input("Enter a number: "))
is_prime = True
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
else:
is_prime = False
if is_prime:
print(num, "is a prime number.")
else:
print(num, "is not a prime number.")
- Temperature Conversion This program converts temperature between Celsius and Fahrenheit.
pythontemp = float(input("Enter the temperature: "))
unit = input("Enter the unit (Celsius or Fahrenheit): ")
converted_temp = None
if unit.lower() == "celsius":
converted_temp = (9 / 5) * temp + 32
print(temp, "Celsius is equal to", converted_temp, "Fahrenheit.")
elif unit.lower() == "fahrenheit":
converted_temp = (5 / 9) * (temp - 32)
print(temp, "Fahrenheit is equal to", converted_temp, "Celsius.")
else:
print("Invalid unit! Please enter Celsius or Fahrenheit.")
Feel free to experiment with these programs, modify them, and see how the results change. Python is a great language for beginners because it allows you to explore and learn through hands-on coding. If you have any questions or need further assistance, feel free to ask!
Comments
Post a Comment