close
習題1的重點:
習題不難~所以不寫了
它的重點是在每一行的開始加入「#」這個的話,就不會印出來了。
語法如下:
puts "Hello World!" puts "Hello Again" #puts "no print"
結果是:
Hello World! Hello Again
就沒有印出 no print了。
習題2的重點:
是在說明#以及注釋的用法
習題3的重點:
先做”計算”再做”比較”
習題4的重點:
說明變數的用法
cars = 100 space_in_a_car = 4.0 drivers = 30 passengers = 90 cars_not_driven = cars - drivers cars_driven = drivers carpool_capacity = cars_driven * space_in_a_car average_passengers_per_car = passengers / cars_driven puts "There are #{cars} cars available." puts "There are only #{drivers} drivers available." puts "There will be #{cars_not_driven} empty cars today." puts "We can transport #{carpool_capacity} people today." puts "We have #{passengers} passengers to carpool today." puts "We need to put about #{average_passengers_per_car} in each car."
cars的值100會被帶入#{cars}裡面
所以所出現的答案如下:
There are 100 cars available. There are only 30 drivers available. There will be 70 empty cars today. We can transport 120.0 people today. We have 90 passengers to carpool today. We need to put about 3 in each car.
文章標籤
全站熱搜
留言列表