answersLogoWhite

0


Best Answer

This can be easily done using the modulo operation (represented by the '%' symbol). This operation gives the remainder of the division of the two numbers used in it.

e.g. 4 % 2 = 0, 5 % 2 = 1, 10 % 3 = 1, 10 % 2 = 0

In a modulo operation, any even number divided by 2 will always have a remainder of 0. This can be done in Python for a number range like so:

current_number = 1 # variable to store the current number being checked

while current_number <= 100: # loop to go through the range of numbers up until 10

if current_number % 2 == 0: # check if the current number has a remainder of 0

print(current_number) # if it does, then print it out

current_number += 1 # move to the next number

This will print out all the even numbers up until 100, each on a separate line.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a python program to print even numbers from 1 to 100 using while loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you make a random number using Python?

this is the code for making a random number using python: import random &gt;&gt;&gt;random.randint (1, 10) you can do whatever numbers you want.


How can you accept sum and print numbers without creating variables?

It is very easy. The program begins here..... /*Program to sum and print numbers without creating variables*/ #include&lt;stdio.h&gt; main() { clrscr(); printf("%d+%d=%d",5,2,5+2); getch(); } /*Program ends here*/ Now just by changing the numbers in the "printf" statement we can add, subtract, multiply and divide the numbers without using variables. Hence the problem is solved..........


Write a program to aceept 5 numbers from keyboard n print itz total?

Sure! Here's a simple Python program that allows the user to input 5 numbers and then calculates and prints their total: numbers = [] for i in range(5): num = int(input(&quot;Enter a number: &quot;)) numbers.append(num) total = sum(numbers) print(&quot;The total is:&quot;, total) This program prompts the user to enter a number 5 times, converts each input to an integer, stores them in a list, calculates the sum of the numbers using the sum() function, and finally prints the total.


Display odd number using for loop?

It is actually quite easy to write a program in java to do this. The easiest way to do this that I can think of is to use the remainder operator (%) to test whether a number is odd or not. Here is a simple program that will print out all the odd numbers between 1 and 50. public class OddNumbers { public static void main(String[] args) { int i=1; while(i &lt; 50) { if(i%2 != 0) { System.out.println(i); } i++; } } }


Write c program to print palindrome using string without using strrev strlen strcam?

sdfdg

Related questions

Write a program using while loop?

//program to find the factorial value f any number using while loop #include&lt;stdio.h&gt; void main() { int i,n,fact=1; printf("Enter the number\n"); scanf("%d",&amp;n); i=n; while (i&gt;=1) { fact=fact*i; i--; } printf("The factorial value=%d",fact); } the above is a program for calculating tha factorial value of any number which is entered by the user


Program for check a number is even or odd using PYTHON language?

This program checks whether a number is odd or even. NOTE: This site removes formatting from answers. Replace (tab) with a tab or four spaces. #!/usr/bin/python print("Type a number.") n = input(": ") l = len(n)-1 even = ("02468") if n[l] in even: (tab)print(n, "is even.") if n[l] not in even: (tab)print(n, "is odd.")


How do you print from compaq laptop?

Use the option File / Print in the program you are using.


How do you make a random number using Python?

this is the code for making a random number using python: import random &gt;&gt;&gt;random.randint (1, 10) you can do whatever numbers you want.


How can you accept sum and print numbers without creating variables?

It is very easy. The program begins here..... /*Program to sum and print numbers without creating variables*/ #include&lt;stdio.h&gt; main() { clrscr(); printf("%d+%d=%d",5,2,5+2); getch(); } /*Program ends here*/ Now just by changing the numbers in the "printf" statement we can add, subtract, multiply and divide the numbers without using variables. Hence the problem is solved..........


Write a program using a loop to output all the letters of the alphabet in uppercase?

Here's the code for your program: # Loop through the uppercase alphabet letters for letter in range(ord('A'), ord('Z') + 1): print(chr(letter)) BTW you can use this code in Python and try it out for yourself.


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


2 Write a program to print a following program?

USING STRING LITERAL VALUES TO ADD 2 NUMBERS If you just want to show the outcome of two numbers you have: PRINT 4 + 5 This will print '9' the answer to 4 + 5. If you want to show the addition: PRINT "4 + 5 = "; 4 + 5 This will show the question and then calculate the answer. If you want the user to input numbers to add, use variables and then add them the same way. ====== COLLECTING USER INPUT FROM THE KEYBOARD/USING NUMERIC VARIABLES In the following example, the end user can get to interact with the program by typing in their numbers at the keyboard; then, pressing the [Enter] key. CLS PRINT "PROGRAM: Add 2 numbers" PRINT INPUT "Enter the 1st number: ", number1 INPUT "Enter the 2nd number: ", number2 PRINT sumTotal=number1+number2 PRINT "The sum total is: "; sumTotal PRINT INPUT "Again, Y/N"; yesNo$ IF UCASE$(LEFT$(yesNo$,1))="Y" THEN RUN END ====== CREATE FUNCTION/THEN, MAKE A FUNCTION CALL TO ADD 2 NUMBERS Another way to write this program is to create a function/then, make a function call... '*** PROGRAM: Add 2 numbers... '*** Variable declaration list... number1=7 '...initialise numeric variable 1 number2=3 '...initialise numeric variable 2 '*** Main program... CLS '...(CL)ear the (S)creen PRINT add(number1,number2) '...make function call/passing in 2 numbers to add END '...END of program/halt program code execution '*** Function(s)... FUNCTION add(num1,num2) '...this line marks the start of the Function add=num1+num2 '...this line returns the sum total of the 2 numbers END FUNCTION '...this line marks the end of the Function


Write a program to Print pyramid of numbers using java?

hi question is here, 1 1 2 1 2 3 1 2 3 4


Write a program to aceept 5 numbers from keyboard n print itz total?

Sure! Here's a simple Python program that allows the user to input 5 numbers and then calculates and prints their total: numbers = [] for i in range(5): num = int(input(&quot;Enter a number: &quot;)) numbers.append(num) total = sum(numbers) print(&quot;The total is:&quot;, total) This program prompts the user to enter a number 5 times, converts each input to an integer, stores them in a list, calculates the sum of the numbers using the sum() function, and finally prints the total.


Program to count the number of numbers in an array using 8085 microprocessor?

A program which is used to count the number of numbers in an array using a 8085 microprocessor is known as a assembly language program.


Display odd number using for loop?

It is actually quite easy to write a program in java to do this. The easiest way to do this that I can think of is to use the remainder operator (%) to test whether a number is odd or not. Here is a simple program that will print out all the odd numbers between 1 and 50. public class OddNumbers { public static void main(String[] args) { int i=1; while(i &lt; 50) { if(i%2 != 0) { System.out.println(i); } i++; } } }