9 Python Programs for Beginners: Learn with Examples!
10 Python Programs for Beginners: Learn with Examples!
Are you ready to embark on your Python programming journey? Let's get started with 9 simple Python programs, each accompanied by an example and explanation:
1. Hello, World!
``` code
print("Hello, World!")
```
The classic introductory program that prints "Hello, World!" to the console.
2. Calculator
``` code
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum = num1 + num2
print("Sum:", sum)
```
Adds two numbers entered by the user and displays the result.
3. Guess the Number
``` code
import random
target = random.randint(1, 100)
guess = int(input("Enter your guess (1-100): "))
if guess == target:
print("Congratulations! You guessed it right.")
else:
print("Sorry, try again!")
```
Generates a random number between 1 and 100. Asks the user to guess the number.
4. Palindrome Checker
``` code
word = input("Enter a word: ")
if word == word[::-1]:
print("Yes, it's a palindrome!")
else:
print("No, it's not a palindrome.")
```
Checks if the entered word is a palindrome.
5. Factorial Calculator
``` code
num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
factorial *= i
print("Factorial of", num, "is", factorial)
Recommended by LinkedIn
```
Calculates the factorial of a given number.
6. Fibonacci Sequence
``` code
n = int(input("Enter the number of terms: "))
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
```
Generates the Fibonacci sequence up to a specified number of terms.
7. Temperature Converter
``` code
temp_celsius = float(input("Enter temperature in Celsius: "))
temp_fahrenheit = (temp_celsius * 9/5) + 32
print("Temperature in Fahrenheit:", temp_fahrenheit)
```
Converts temperature from Celsius to Fahrenheit.
8. Word Counter
``` code
sentence = input("Enter a sentence: ")
words = sentence.split()
print("Number of words:", len(words))
```
Counts the number of words in a given sentence.
9. Prime Number Checker
``` code
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, num):
if (num % i) == 0:
print(num, "is not a prime number.")
break
else:
print(num, "is a prime number.")
else:
print(num, "is not a prime number.")
```
Checks if a given number is prime or not.
Start exploring Python with these beginner-friendly programs today! Happy coding! #PythonProgramming #BeginnerProjects #CodingByExample
Follow my newsletter superbrain for AI trends and news.
ok
Helpful! This will