Skip to content

Instantly share code, notes, and snippets.

@maeharin
Created May 11, 2012 10:11
Show Gist options
  • Save maeharin/2658743 to your computer and use it in GitHub Desktop.
Save maeharin/2658743 to your computer and use it in GitHub Desktop.
Ruby/Python基礎練習
# -*- coding: utf-8 -*-
#バージョンは、Python 2.7.1
# スカラー
number1 = 3
number2 = 4
result = number1 + number2
print result
# 配列
foods = ['ラーメン', '寿司', 'カレー'];
for i in foods:
print i
#ハッシュ
ore = {
'name' : 'maeharin',
'tall' : 169
}
for i in ore:
print i + '::' + str(ore[i])
#配列+ハッシュ
people = [
{
'name' : 'Kさん',
'tall' : 160
},
{
'name' : 'Yさん',
'tall' : 182
}
]
for i in people:
for k,v in i.items():
print k, v
# 配列+ハッシュ+配列
people = [
{
'name' : 'kさん',
'foods' : ['barger', 'ramen']
},
{
'name' : 'yさん',
'foods' : ['sushi', 'chikin']
}
]
for i in people:
for j in i['foods']:
print i['name'] + j
#バージョンは、ruby 1.8.7
#スカラー
number1 = 3
number2 = 4
result = number1 + number2
puts result
#配列
foods = ['ラーメン', '寿司', 'カレー']
for i in foods
puts i
end
#ハッシュ
ore = {
:name => 'maeharin',
:tall => '169'
}
ore.each do |k, v|
print k , "::", v , "\n"
end
#配列+ハッシュ
people = [
{
:name => 'Kさん',
:tall => '160'
},
{
:name => 'Yさん',
:tall => 182
}
]
for i in people
i.each do |k,v|
print k, ":" , v, "\n"
end
end
#配列+ハッシュ+配列
people = [
{
:name => 'Kさん',
:foods => ['カレー', 'ラーメン']
},
{
:name => 'Yさん',
:foods => ['ハンバーガー', '牛丼', 'チキン']
}
]
for i in people
for j in i[:foods]
print i[:name], 'は', j , "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment