5 basic Python programs for beginners

Hello, World!

print("Hello, World!")

This is the classic introductory program that simply prints "Hello, World!" to the console. It helps you verify that your Python environment is set up correctly.

Simple Calculator

num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) sum = num1 + num2 print("Sum:", sum) difference = num1 - num2 print("Difference:", difference) product = num1 * num2 print("Product:", product) quotient = num1 / num2 print("Quotient:", quotient)

This program prompts the user to enter two numbers and performs basic arithmetic operations like addition, subtraction, multiplication, and division.

Guessing Game

import random number = random.randint(1, 10) guess = int(input("Guess a number between 1 and 10: ")) if guess == number:    print("Congratulations! You guessed it right.") else:    print("Sorry, wrong guess. The number was", number)

In this program, the computer generates a random number between 1 and 10, and the user tries to guess the number. It provides feedback on whether the guess was correct or not.

Check Prime Number

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.")

This program checks if a given number is prime or not. It uses a simple loop to iterate through numbers and checks for divisibility.

Fibonacci Series

n = int(input("Enter the number of terms: ")) a, b = 0, 1 print("Fibonacci Series:") print(a, end=" ") for _ in range(n - 1):    print(b, end=" ")    a, b = b, a + b

This program generates the Fibonacci series up to a specified number of terms. It uses a loop and two variables to calculate and display the series.

These programs cover basic concepts like input/output, arithmetic operations, conditional statements, loops, and using libraries. They provide a good starting point for beginners to practice and understand Python programming.

Thank you