לימוד פייתון לאיש הפשוט/לספור עד 10: הבדלים בין גרסאות בדף
תוכן שנמחק תוכן שנוסף
שורה 32:
זיכרו תמיד לשים נקודתיים ":" אחרי "while"!
הנה עוד דוגמה לשימוש ב <code>while</code>:
<div style="direction: ltr;">
<source lang="python">
a = 1
s = 0
print 'Enter Numbers to add to the sum.'
print 'Enter 0 to quit.'
while a != 0:
print 'Current Sum:', s
a = input('Number? ')
s = s + a
print 'Total Sum =', s
</source>
Enter Numbers to add to the sum.
Enter 0 to quit.
Current Sum: 0
Number? '''200'''
Current Sum: 200
Number? '''-15.25'''
Current Sum: 184.75
Number? '''-151.85'''
Current Sum: 32.9
Number? '''10.00'''
Current Sum: 42.9
Number? '''0'''
Total Sum = 42.9
</div>
== דוגמאות ==
|