what is the output ? count = 0
while count < 5:
print(count) count += 1
while count < 5:
print(count) count += 1
Anonymous Quiz
10%
1 2 3 4 5
14%
0 1 2 3 4 5
75%
0 1 2 3 4
👏4
2. what is the output ? num = 10
while num >= 0:
print(num) num -= 2 or we can say num = num -2
while num >= 0:
print(num) num -= 2 or we can say num = num -2
Anonymous Quiz
5%
10 9 8 7 6 5 4 3 2 1
23%
10 8 6 4 2
72%
10 8 6 4 2 0
#Day_note The modulo operator, denoted by the symbol
For example, if we have the expression
Here are a few examples to illustrate the usage of the modulo operator:
1.
2.
3.
%, is a mathematical operator that returns the remainder of a division operation. It is used to determine the remainder when one number is divided by another.For example, if we have the expression
a % b, the modulo operator will divide a by b and return the remainder.Here are a few examples to illustrate the usage of the modulo operator:
1.
10 % 3 returns 1 because when 10 is divided by 3, the remainder is 1.2.
15 % 4 returns 3 because when 15 is divided by 4, the remainder is 3.3.
7 % 2 returns 1 because when 7 is divided by 2, the remainder is 1.👍7
Write a program that takes an input from the user and determines whether the number is even or odd. The program should display a message indicating the result.
Your program should perform these tasks: 1. take input from the user and say even or odd and take input from the user again...
hint Use the modulo operator and while loop
Your program should perform these tasks: 1. take input from the user and say even or odd and take input from the user again...
hint Use the modulo operator and while loop
👍1
Leetcode with dani pinned «What is a while loop in Python? While loop is a control flow statement that allows you to repeatedly execute a block of code as long as a certain condition is true. It is useful when you want to repeat a specific task until a certain condition is met. The…»
Leetcode with dani
Write a program that takes an input from the user and determines whether the number is even or odd. The program should display a message indicating the result. Your program should perform these tasks: 1. take input from the user and say even or…
while True:
number = int(input("Enter a number: "))
if number % 2 == 0:
print(number, "is even.")
else:
print(number, "is odd.")❤5⚡1
1. What is the output of the following code snippet?
x = 5
while x >= 0: print(x) x -= 1
x = 5
while x >= 0: print(x) x -= 1
Anonymous Quiz
20%
5 4 3 2 1
6%
1 2 3 4 5
61%
5 4 3 2 1 0
13%
0 1 2 3 4 5
❤🔥1
1. What is the output of the following code snippet?
x = 10
while x > 0: if x % 2 == 0: print(x) x -= 1
x = 10
while x > 0: if x % 2 == 0: print(x) x -= 1
Anonymous Quiz
73%
10 8 6 4 2
9%
2 4 6 8 10
10%
10 9 8 7 6 5 4 3 2 1
8%
1 3 5 7 9
3. What is the output of the following code snippet?
count = 0
while count < 5: count += 1 if count == 3: break print(count)
count = 0
while count < 5: count += 1 if count == 3: break print(count)
Anonymous Quiz
8%
a) 1 2 3 4 5
16%
b) 1 2 4 5
12%
c) 1 2 3 4
63%
d) 1 2
❤3
4. What is the output of the following code snippet?
x = 1
while x <= 5: print(x) x += 2
x = 1
while x <= 5: print(x) x += 2
Anonymous Quiz
10%
a) 1 2 3 4 5
77%
b) 1 3 5
7%
c) 2 4 6
6%
d) 1 2 4
#code_challenge try to create a program that checks the password of a user, if the password is correct it should say welcome. if the password is not correct it should ask to re-write your password. by using while loop and if else condition
👍3❤1
Leetcode with dani
#code_challenge try to create a program that checks the password of a user, if the password is correct it should say welcome. if the password is not correct it should ask to re-write your password. by using while loop and if else condition
Please submit your assignments through the bot by the designated deadline. @zprogramming_bot
👍4
Ke memeberachn yetelaku arif melsoch:
User_password = "1q2w3e"
Count = 0
while Count < 3:
Login = input("Enter your password: ")
if User_password == Login:
print("Welcome")
break
else:
print("Try again")
Count += 1
if Count == 3:
print("Locked")
User_password = "1q2w3e"
Count = 0
while Count < 3:
Login = input("Enter your password: ")
if User_password == Login:
print("Welcome")
break
else:
print("Try again")
Count += 1
if Count == 3:
print("Locked")
👍9
Forwarded from Deleted Account
def check_password():
password = "eul"
attempts = 0
while attempts < 3:
user_input = input("Enter your password: ")
if user_input == password:
print("welcome!")
break
else:
print("Incorrect password, please try again.")
attempts += 1
if attempts == 3:
print("You have exceeded the maximum number of attempts. Exiting the program...")
check_password()
password = "eul"
attempts = 0
while attempts < 3:
user_input = input("Enter your password: ")
if user_input == password:
print("welcome!")
break
else:
print("Incorrect password, please try again.")
attempts += 1
if attempts == 3:
print("You have exceeded the maximum number of attempts. Exiting the program...")
check_password()
❤6👍5
for loop in Python:The
for loop is used to iterate over a sequence (such as a list, tuple, string, or range) or any other iterable object. It allows you to execute a block of code repeatedly for each item in the sequence.The general syntax of a
for loop is as follows:for item in sequence:
# code to be executed for each item
Here's a breakdown of how the
for loop works:1. The loop starts by assigning the first item in the sequence to the variable
item.2. The code block inside the loop is executed for the current
item.3. After executing the code block, the loop moves on to the next item in the sequence and repeats steps 2 and 3 until all items have been processed.
4. Once all items have been processed, the loop terminates, and the program continues with the next line of code after the loop.
Here's an example to illustrate the usage of a
for loop:fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
In this example, the
for loop iterates over each item in the fruits list. For each iteration, the current fruit is assigned to the variable fruit, and the print(fruit) statement is executed, which prints the fruit to the console. The loop continues until all fruits have been processed.The output of the above code will be:
apple
banana
cherry
You can also use the
range() function to generate a sequence of numbers to iterate over. For example:for i in range(1, 5):
print(i)
This will print the numbers 1, 2, 3, and 4.
👍3❤2
how the
The
Let's take a look at the general syntax of a
Here's a breakdown of how the
1. The loop starts by assigning the first item in the list to the variable
2. The code block inside the loop is executed for the current
3. After executing the code block, the loop moves on to the next item in the list and repeats steps 2 and 3 until all items have been processed.
4. Once all items have been processed, the loop terminates, and the program continues with the next line of code after the loop.
Here's an example to illustrate the usage of a
In this example, the
The output of the above code will be:
You can also perform various operations on each item in the list within the loop. For example, you can manipulate the items, perform calculations, or update values.
Here's an example that demonstrates updating the values of a list using a
In this example, the
The output of the above code will be:
for loop works with a list in Python:The
for loop is commonly used to iterate over a list, which is an ordered collection of items. It allows you to perform a specific action for each item in the list.Let's take a look at the general syntax of a
for loop with a list:for item in list:
# code to be executed for each item
Here's a breakdown of how the
for loop works with a list:1. The loop starts by assigning the first item in the list to the variable
item.2. The code block inside the loop is executed for the current
item.3. After executing the code block, the loop moves on to the next item in the list and repeats steps 2 and 3 until all items have been processed.
4. Once all items have been processed, the loop terminates, and the program continues with the next line of code after the loop.
Here's an example to illustrate the usage of a
for loop with a list:fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
In this example, the
for loop iterates over each item in the fruits list. For each iteration, the current fruit is assigned to the variable fruit, and the print(fruit) statement is executed, which prints the fruit to the console. The loop continues until all fruits have been processed.The output of the above code will be:
apple
banana
cherry
You can also perform various operations on each item in the list within the loop. For example, you can manipulate the items, perform calculations, or update values.
Here's an example that demonstrates updating the values of a list using a
for loop:numbers = [1, 2, 3, 4, 5]
for i in range(len(numbers)):
numbers[i] = numbers[i] * 2
print(numbers)
In this example, the
for loop iterates over each index of the numbers list using the range() function. For each iteration, the current index is assigned to the variable i, and the value at that index is multiplied by 2 and updated in the list. Finally, the updated list is printed to the console.The output of the above code will be:
[2, 4, 6, 8, 10]👍4
Leetcode with dani pinned «for loop in Python: The for loop is used to iterate over a sequence (such as a list, tuple, string, or range) or any other iterable object. It allows you to execute a block of code repeatedly for each item in the sequence. The general syntax of a for loop…»
3. What is the output of the following code snippet?
for num in range(3, 10, 2):
print(num)
for num in range(3, 10, 2):
print(num)
Anonymous Quiz
76%
A) 3, 5, 7, 9
12%
B) 2, 4, 6, 8
8%
C) 3, 6, 9
3%
D) 2, 5, 8
👍3
2.How does a for loop work with a list in Python?
Anonymous Quiz
81%
A) It iterates over each item in the list and performs a specific action for each item.
6%
B) It updates the values in the list .
12%
C) It generates a sequence of numbers based on the list elements.
1%
D) It reverses the order of the list elements.
👍3