7 תשובות
# initialize number
num = -10

# while loop until num is greater than -28
while num > -28:
print(num)
num -= 3
שואל השאלה:
יש לי עוד שאלה (אחרת):
התוכנית קולטת מהמקלדת מספר ומדפיסה את כל הכפולות שלו מ-1 עד 10.
# ask the user for a number
num = int(input("enter a number: "))

# for each number from 1 to 10
for i in range(1, 11):
# print the multiple
print(num, "x", i, "=", num * i)
שואל השאלה:
שאלה אחרונה (אחרת):
התוכנית קולטת מספר ומדפיסה כמה ספרות יש למספר. לדוגמא, עבור המספר 1,240 תדפיס 4 ועבור המספר 78
תדפיס 2.
דרך קצרה:
# ask the user for a number
num = input("enter a number: ")

# remove any potential commas
num = num.replace(',', '')

# check if the input is a number
if num.isdigit():
# print the number of digits
print("number of digits:", len(num))
else:
print("invalid input. please enter a number.")


דרך ארוכה:
# ask the user for a number
num = input("enter a number: ")

# remove any commas from the string
num = num.replace(',', '')

# initialize digit counter
digit_count = 0

# for each character in the string
for char in num:
# check if the character is a digit
if char.isdigit():
# increment the digit counter
digit_count += 1

# print the number of digits
print("number of digits:", digit_count)
שואל השאלה:
תודה רבה