[go: up one dir, main page]

0% found this document useful (0 votes)
2 views3 pages

3

The document provides five Python code examples for various purposes: generating Fibonacci sequences, a number guessing game, a temperature converter, a factorial calculator, and a countdown timer. Each example includes code snippets and brief descriptions of their functionality. It also invites the reader to request additional code examples for specific topics like web scraping or data analysis.

Uploaded by

hsgstgas
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 views3 pages

3

The document provides five Python code examples for various purposes: generating Fibonacci sequences, a number guessing game, a temperature converter, a factorial calculator, and a countdown timer. Each example includes code snippets and brief descriptions of their functionality. It also invites the reader to request additional code examples for specific topics like web scraping or data analysis.

Uploaded by

hsgstgas
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/ 3

Got it!

Here are **five more Python code examples** with different


:purposes

**Fibonacci Sequence Generator** .1 ###

.Generates the first *n* numbers of the Fibonacci sequence

python```

N = int(input("Enter the number of Fibonacci terms: "))

A, b = 0, 1

:For _ in range(n)

Print(a, end=' ')

A, b = b, a + b

```

**Simple Number Guessing Game** .2 ###

.Guess a randomly generated number between 1 and 10

python```

Import random

Secret = random.randint(1, 10)

Guess = int(input("Guess a number between 1 and 10: "))

:If guess == secret

Print("Correct! You guessed it!")

:Else

Print(f"Wrong! The number was {secret}.")

```
**Temperature Converter (Celsius ↔ Fahrenheit)** .3 ###

python```

Choice = input("Convert from ©elsius or (F)ahrenheit?


)(").strip().upper

Temp = float(input("Enter the temperature: "))

:'If choice == 'C

Converted = (temp * 9/5) + 32

Print(f"{temp}°C = {converted}°F")

:'Elif choice == 'F

Converted = (temp – 32) * 5/9

Print(f"{temp}°F = {converted}°C")

:Else

Print("Invalid choice.")

```

**Factorial Calculator** .4 ###

.Calculates the factorial of a number

python```

:Def factorial(n)

Return 1 if n == 0 else n * factorial(n – 1)

Num = int(input("Enter a number to find Its factorial: "))

Print(f"Factorial of {num} Is {factorial(num)}")

```
**Countdown Timer** .5 ###

.Counts down from a specified number of seconds

python```

Import time

Seconds = int(input("Enter countdown time in seconds: "))

:For I in range(seconds, 0, -1)

Print(i)

Time.sleep(1)

Print("Time's up!")

```

Do you want codes for web scraping, data analysis, game


!development, or something else? Let me know

You might also like