לימוד פייתון לאיש הפשוט/מי שם?: הבדלים בין גרסאות בדף

תוכן שנמחק תוכן שנוסף
Ayah (שיחה | תרומות)
אין תקציר עריכה
Ayah (שיחה | תרומות)
שורה 140:
 
== דוגמאות ==
הדוגמה הראשונה מחשבת את הזמן שיקח עבור מהירות ומרחק נתונים, יש להקליד את המהירות ואח"כ את המרחק:
<div style="direction: ltr;">
 
'''Rate_times.py'''
<source lang="python">
# This program calculates rate and distance problems
print "Input a rate and a distance"
rate = input("Rate: ")
distance = input("Distance: ")
print "Time: ", (distance / rate)
</source>
 
</div>
הדוגמה תריץ:
<div style="direction: ltr;">
 
Input a rate and a distance
Rate: '''5'''
Distance: '''10'''
Time: 2
 
Input a rate and a distance
Rate: '''3.52'''
Distance: '''45.6'''
Time: 12.9545454545
</div>
הדוגמה הבאה מחשבת את ההקף והשטח של מלבן נתון, יש להקליד קודם את אורך המלבן ואח"כ את רוחבו:
<div style="direction: ltr;">
'''Area.py'''
<source lang="python">
# This program calculates the perimeter and area of a rectangle
print "Calculate information about a rectangle"
length = input("Length: ")
width = input("Width: ")
print "Area", length * width
print "Perimeter", 2 * length + 2 * width
</source>
</div>
הדוגמה תריץ:
<div style="direction: ltr;">
Calculate information about a rectangle
Length: '''4'''
Width: '''3'''
Area 12
Perimeter 14
 
Calculate information about a rectangle
Length: '''2.53'''
Width: '''5.2'''
Area 13.156
Perimeter 15.46
</div>
הדוגמה הבאה ממירה את הטמפרטורה מפרנהייט לצלזיוס, יש להקליד את הטמפ' בפרנהייט:
<div style="direction: ltr;">
'''temperature.py'''
<source lang="python">
# Converts Fahrenheit to Celsius
temp = input("Fahrenheit temperature: ")
print (temp - 32.0) * 5.0 / 9.0
</source>
</div>
הדוגמא תריץ:
 
<div style="direction: ltr;">
Fahrenheit temperature: '''32'''
0.0
 
Fahrenheit temperature: '''-40'''
-40.0
 
Fahrenheit temperature: '''212'''
100.0
 
Fahrenheit temperature: '''98.6'''
37.0
</div>
== תרגילים ==