some program with python

 


Sure! Here's a simple Python program that prompts the user to enter two numbers and then computes their sum:

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

sum = num1 + num2

print("The sum of", num1, "and", num2, "is", sum)

When you run this program, it will ask the user to enter two numbers. The float function is used to convert the user input into a floating-point number, which allows the program to handle decimal values as well as whole numbers.

The program then adds the two numbers together and stores the result in the sum variable. Finally, it uses the print function to display a message that includes the original numbers and their sum.

Here's an example of what the output might look like:

Enter first number: 3.5

Enter second number: 6.2

The sum of 3.5 and 6.2 is 9.7

Sure, here's an example program in Python to print out a multiplication table:

# get input from user for size of table

size = int(input("Enter size of table: "))

 

# print header row

print("x", end="\t")

for i in range(1, size+1):

    print(i, end="\t")

print()

 

# print table rows

for i in range(1, size+1):

    print(i, end="\t")

    for j in range(1, size+1):

        print(i*j, end="\t")

    print()

In this program, we first ask the user to enter the size of the table they want. Then, we print out the header row, which consists of the numbers from 1 to the size of the table. After that, we print out the rows of the table by iterating through the numbers from 1 to the size of the table and multiplying each number by the other numbers in the range, and printing out the result. The result is printed in a table format, using the "\t" character to separate the columns.

Commentaires