Write a python program to input a number and print its five first mult...
Python Program to Print Five First Multiples of a Number
To print the five first multiples of a number in Python, we need to take the input from the user and then calculate the multiples using a loop. The loop will run five times and print the result each time.
Steps to Write the Program:
1. Take input from the user using the input() function and store it in a variable.
2. Convert the input to an integer using the int() function.
3. Initialize a variable to store the result of each multiple.
4. Use a for loop to calculate the five first multiples of the input number.
5. Print the result of each multiple.
Python Code:
```
num = int(input("Enter a number: "))
result = 0
for i in range(1, 6):
result = num * i
print(num, "x", i, "=", result)
```
Explanation:
The program starts by taking input from the user using the input() function and storing it in the variable "num". We then convert the input to an integer using the int() function.
Next, we initialize a variable "result" to store the result of each multiple. We use a for loop to calculate the five first multiples of the input number. The loop runs from 1 to 5, and each time it calculates the multiple by multiplying the input number with the loop variable "i". The result is stored in the "result" variable.
Finally, we use the print() function to print the result of each multiple. We print the input number, the loop variable "i", and the result of the multiplication using the string concatenation operator "+".
This program will take the input number from the user and print its five first multiples.
Write a python program to input a number and print its five first mult...
N= int(input("enter number:"))
for a in range(1,6):
print(n*a)
Please check that you use the print statement in correct indentation. It will be placed below 'a'
To make sure you are not studying endlessly, EduRev has designed Class 11 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 11.