text
stringlengths 0
312
|
---|
# write a python program to add two numbers |
num1 = 1.5 |
num2 = 6.3 |
sum = num1 + num2 |
print(f'Sum: {sum}') |
# write a python function to add two user provided numbers and return the sum |
def add_two_numbers(num1, num2): |
sum = num1 + num2 |
return sum |
# write a program to find and print the largest among three numbers |
num1 = 10 |
num2 = 12 |
num3 = 14 |
if (num1 >= num2) and (num1 >= num3): |
largest = num1 |
elif (num2 >= num1) and (num2 >= num3): |
largest = num2 |
else: |
largest = num3 |
print(f'largest:{largest}') |
# write a program to find and print the smallest among three numbers |
num1 = 10 |
num2 = 12 |
num3 = 14 |
if (num1 <= num2) and (num1 <= num3): |
smallest = num1 |
elif (num2 <= num1) and (num2 <= num3): |
smallest = num2 |
else: |
smallest = num3 |
print(f'smallest:{smallest}') |
# Write a python function to merge two given lists into one |
def merge_lists(l1, l2): |
return l1 + l2 |
# Write a program to check whether a number is prime or not |
num = 337 |
if num > 1: |
for i in range(2, num//2 + 1): |
if (num % i) == 0: |
print(num,"is not a prime number") |
print(f"{i} times {num//i} is {num}") |
break |
else: |
print(f"{num} is a prime number") |
else: |
print(f"{num} is not a prime number") |
# Write a python function that prints the factors of a given number |
def print_factors(x): |
print(f"The factors of {x} are:") |
for i in range(1, x + 1): |
if x % i == 0: |
print(i) |
# Write a program to find the factorial of a number |
num = 13 |
factorial = 1 |
if num < 0: |
print("No factorials for negative numbers!") |
elif num == 0: |
print("The factorial of 0 is 1") |
else: |
for i in range(1,num + 1): |
factorial = factorial*i |
print(f"The factorial of {num} is {factorial}") |
# Write a python function to print whether a number is negative, positive or zero |
def check_pnz(num): |
if num > 0: |
print("Positive number") |
elif num == 0: |
print("Zero") |
else: |
print("Negative number") |
# Write a program to print the multiplication table of a given number |
num = 9 |
for i in range(1, 11): |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 33