708
Подписчики
Нет данных24 часа
-17 дней
-530 день
Архив постов
708
Sum of Numbers
Write a Python program to find the sum of all numbers from 1 to n, where n is a positive integer provided by the user.
python
n = int(input("Enter a positive integer: "))
total = sum(range(1, n + 1))
print(f"The sum of numbers from 1 to {n} is {total}.")
Factorial Calculation
Write a Python program to calculate the factorial of a number n using a loop.
python
n = int(input("Enter a number: "))
factorial = 1
for i in range(1, n + 1):
factorial *= i
print(f"The factorial of {n} is {factorial}.")
Palindrome Check
Write a Python program to check if a given string is a palindrome.
python
s = input("Enter a string: ")
if s == s[::-1]:
print(f"'{s}' is a palindrome.")
else:
print(f"'{s}' is not a palindrome.")
Fibonacci Sequence
Write a Python program to generate the first n numbers in the Fibonacci sequence.
python
n = int(input("Enter the number of Fibonacci terms to generate: "))
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a + b
print()
Prime Number Check
Write a Python program to check if a given number is a prime number.
python
n = int(input("Enter a number: "))
if n > 1:
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
print(f"{n} is not a prime number.")
break
else:
print(f"{n} is a prime number.")
else:
print(f"{n} is not a prime number.")
List Reversal
Write a Python program to reverse a given list.
python
lst = [int(x) for x in input("Enter a list of numbers separated by spaces: ").split()]
reversed_lst = lst[::-1]
print("Reversed list:", reversed_lst)
Count Vowels in a String
Write a Python program to count the number of vowels in a given string.
python
s = input("Enter a string: ")
vowels = 'aeiou'
count = sum(1 for char in s.lower() if char in vowels)
print(f"The number of vowels in the string is {count}.")
Temperature Conversion
Write a Python program to convert temperature from Celsius to Fahrenheit.
python
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print(f"{celsius} Celsius is equal to {fahrenheit} Fahrenheit.")
Multiplication Table
Write a Python program to display the multiplication table of a number n.
python
n = int(input("Enter a number to display its multiplication table: "))
for i in range(1, 11):
print(f"{n} x {i} = {n * i}")
Remove Duplicates from a List
Write a Python program to remove duplicates from a list.
python
lst = [int(x) for x in input("Enter a list of numbers separated by spaces: ").split()]
unique_lst = list(set(lst))
print("List after removing duplicates:", unique_lst)
708
Keywords in python are
The list of keywords are:
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break',
'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
708
Python
is a widely used general-purpose, high level programming language. It was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with an emphasis on code readability, and its syntax allows programmers to express their concepts in fewer lines of code. Python is a programming language that lets you work quickly and integrate systems more efficiently. There are two major Python versions: Python 2 and Python 3. Both are quite different.
