Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Here are 10 Python programs covering various concepts

Here are 10 Python programs covering various concepts

Become More Then A coder | Learn & Start Coding Now.

 Here are 10 Python programs covering various concepts:


### 1. Program to Find the Factorial of a Number:

```python
# Program 1: Factorial Calculation
def factorial(n):
    if n == 0 or n == 1:
        return 1
    return n * factorial(n - 1)

number = int(input("Enter a number to find its factorial: "))
result = factorial(number)
print(f"The factorial of {number} is: {result}")
```

### 2. Program to Check if a Number is Prime:

```python
# Program 2: Prime Number Check
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

number = int(input("Enter a number to check if it's prime: "))
result = "prime" if is_prime(number) else "not prime"
print(f"{number} is {result}.")
```

### 3. Program to Reverse a String:

```python
# Program 3: String Reversal
def reverse_string(input_str):
    return input_str[::-1]

user_input = input("Enter a string to reverse: ")
result = reverse_string(user_input)
print(f"The reversed string is: {result}")
```

### 4. Program to Calculate the Fibonacci Sequence:

```python
# Program 4: Fibonacci Sequence
def fibonacci(n):
    fib_sequence = [0, 1]
    while len(fib_sequence) < n:
        fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
    return fib_sequence

length = int(input("Enter the length of the Fibonacci sequence: "))
result = fibonacci(length)
print(f"The Fibonacci sequence up to {length} terms is: {result}")
```

### 5. Program to Convert Celsius to Fahrenheit:

```python
# Program 5: Celsius to Fahrenheit Conversion
def celsius_to_fahrenheit(celsius):
    return (celsius * 9/5) + 32

temp_celsius = float(input("Enter temperature in Celsius: "))
temp_fahrenheit = celsius_to_fahrenheit(temp_celsius)
print(f"{temp_celsius} degrees Celsius is equal to {temp_fahrenheit} degrees Fahrenheit.")
```

### 6. Program to Find the Largest Element in a List:

```python
# Program 6: Find the Largest Element in a List
def find_largest_element(lst):
    return max(lst)

numbers = [int(x) for x in input("Enter numbers separated by space: ").split()]
result = find_largest_element(numbers)
print(f"The largest element in the list is: {result}")
```

### 7. Program to Count the Occurrences of Each Word in a String:

```python
# Program 7: Word Count in a String
def count_word_occurrences(sentence):
    words = sentence.split()
    word_count = {word: words.count(word) for word in set(words)}
    return word_count

user_sentence = input("Enter a sentence: ")
result = count_word_occurrences(user_sentence)
print("Word occurrences in the sentence:")
for word, count in result.items():
    print(f"{word}: {count}")
```

### 8. Program to Implement Bubble Sort:

```python
# Program 8: Bubble Sort
def bubble_sort(lst):
    n = len(lst)
    for i in range(n):
        for j in range(0, n-i-1):
            if lst[j] > lst[j+1]:
                lst[j], lst[j+1] = lst[j+1], lst[j]

numbers = [int(x) for x in input("Enter numbers separated by space: ").split()]
bubble_sort(numbers)
print(f"Sorted list using Bubble Sort: {numbers}")
```

### 9. Program to Calculate the Area of a Triangle:

```python
# Program 9: Triangle Area Calculation
def calculate_triangle_area(base, height):
    return 0.5 * base * height

triangle_base = float(input("Enter the base of the triangle: "))
triangle_height = float(input("Enter the height of the triangle: "))
area = calculate_triangle_area(triangle_base, triangle_height)
print(f"The area of the triangle is: {area}")
```

### 10. Program to Generate a Random Password:

```python
# Program 10: Random Password Generator
import random
import string

def generate_random_password(length):
    characters = string.ascii_letters + string.digits + string.punctuation
    password = ''.join(random.choice(characters) for _ in range(length))
    return password

password_length = int(input("Enter the length of the password: "))
random_password = generate_random_password(password_length)
print(f"Generated Random Password: {random_password}")
```

Feel free to run and experiment with these programs to enhance your understanding of Python programming concepts!

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.