dividen

언어/비교2016. 3. 25. 12:31

Ruby

# [1]더하기
def addition(num1, num2)
printf("#{num1} + #{num2} = #{num1+ num2} \n")
end

# [2]빼기
def subtraction(num1, num2)
printf("#{num1} - #{num2} = #{num1 - num2} \n")
end

# [3]곱하기
def multiplication(num1, num2)
printf("#{num1} x #{num2} = #{num1*num2} \n")
end

# [4]나누기
def dividen(num1, num2)
printf("#{num1} / #{num2} = #{num1/num2} \n")
end
#--------------------------------
def main
print "number1 input >> "
number1 = gets.chomp.to_i
print "number2 input >> "
number2 = gets.chomp.to_i

addition(number1, number2)
subtraction(number1, number2)
multiplication(number1, number2)
dividen(number1, number2)
end

main()


Go

package main
import "C"
import "fmt"

func add(data1 int, data2 int) {
fmt.Printf("%d + %d = %d\n", data1, data2, data1+data2)
}
func sub(data1 int, data2 int) {
fmt.Printf("%d - %d = %d\n", data1, data2, data1-data2)
}
func mul(data1 int, data2 int) {
fmt.Printf("%d x %d = %d\n", data1, data2, data1*data2)
}
func div(data1 int, data2 int) {
fmt.Printf("%.2f / %.2f = %.2f\n",
float64(data1), float64(data2), float64(data1)/float64(data2))
}

func main() {
var data int = 10
var data1 int = 20
var data_pointer *int
data_pointer = &data
fmt.Println(data)
fmt.Println(data_pointer)
fmt.Println(*data_pointer) //* important
add(data, data1)
sub(data, data1)
mul(data, data1)
div(data, data1)
}

python

def summation(value1, value2):
print("{0:d} + {1:d} = {2:d}".format(value1, value2, value1+value2))
def subtraction(value1, value2):
print("{0:d} - {1:d} = {2:d}".format(value1, value2, value1-value2))
def multiplication(value1, value2):
print("{0:d} x {1:d} = {2:d}".format(value1, value2, value1*value2))
def dividen(value1, value2):
print("{0:d} / {1:d} = {2:.2f}".format(value1, value2, value1/value2))
def main():
value_1 = int(input("value1 input >>> "))
value_2 = int(input("value2 input >>> "))
summation(value_1,value_2)
subtraction(value_1, value_2)
multiplication(value_1, value_2)
dividen(value_1, value_2)
if __name__ =="__main__":
main()



'언어 > 비교' 카테고리의 다른 글

python go [python이 확실히 더 직관적이다.] 루비는 다시 볼 것  (0) 2016.02.26
python vs ruby  (0) 2016.02.13
python vs ruby  (0) 2016.02.13
ruby vs python  (0) 2016.02.10

<<<<<<<<<<<<<<<<<<<<<< python >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
print
(" ============= << AND >> ===============")
print("True and True =>", True and True)
print("True and False =>",True and False)
print("False and True =>",False and True)
print("False and False =>",False and False)
print(" ============= << OR >> ===============")
print("True OR True =>",True or True)
print("True OR False =>",True or False)
print("False OR True =>",False or True)
print("False OR False =>",False or False)
print(" ============= << NOT >> ===============")
print(not True)
print(not False)


<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GO >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package
main
import "fmt"
func main() {
fmt.Println(" ====== OR ==============")
fmt.Println(" true OR true =>", true || true) // 1 or 1 = 1
fmt.Println(" true OR false =>", true || false) // 1 or 0 = 1
fmt.Println(" false OR true =>", false || true) // 0 or 1 = 1
fmt.Println(" false OR false =>", false || false) // 0 or 0 = 0
fmt.Println(" ====== AND =============")
fmt.Println(" true AND true =>", true && true) // 1 and 1 = 1
fmt.Println(" true AND false=>", true && false) // 1 and 0 = 0
fmt.Println(" false AND true =>", false && true) // 0 and 1 = 0
fmt.Println(" false AND false=>", false && false) // 0 and 0 = 0
fmt.Println(" ====== NOT =============")
fmt.Println(" !true " , !true)
fmt.Println(" !false ",!false)
}



< 루비 >

puts " <<< AND >>>"
puts true and true
puts true and false
puts false and true
puts false and false
puts " <<< && >>>"
puts true && true
puts true && false
puts false && true
puts false && false
puts " <<< OR >>> "
puts true or true
puts true or false
puts false or true
puts false or false
puts " <<< || >>>"
puts true || true
puts true || false
puts false || true
puts false || false

 <<< AND >>>
true
true
false
false
 <<< && >>>
true
false
false
false
 <<< OR >>>
true
true
false
false
 <<< || >>>
true
true
true
false


puts "true and true => ", TRUE and TRUE
puts "false and true => ", FALSE and TRUE
puts "true and false => ", TRUE and FALSE
puts "false and false => ", FALSE and FALSE

puts "true or true => ", TRUE or TRUE
puts "false or true => ", FALSE or TRUE
puts "true or false => ", TRUE or FALSE
puts "false or false => ", FALSE or FALSE

puts "not true => ", !true
puts "not false => ", !false



'언어 > 비교' 카테고리의 다른 글

dividen  (0) 2016.03.25
python vs ruby  (0) 2016.02.13
python vs ruby  (0) 2016.02.13
ruby vs python  (0) 2016.02.10

python vs ruby

언어/비교2016. 2. 13. 10:24

여기서 중요하게 생각할것은  gets.chomp.to_i

to_i 에서   i 는 정수 integer를 뜻하는 것 같다.



'언어 > 비교' 카테고리의 다른 글

dividen  (0) 2016.03.25
python go [python이 확실히 더 직관적이다.] 루비는 다시 볼 것  (0) 2016.02.26
python vs ruby  (0) 2016.02.13
ruby vs python  (0) 2016.02.10

python vs ruby

언어/비교2016. 2. 13. 08:24

important:   names.each do |name| 루비에서는 for문을 이런식으로 많이 사용한다고 한다.




'언어 > 비교' 카테고리의 다른 글

dividen  (0) 2016.03.25
python go [python이 확실히 더 직관적이다.] 루비는 다시 볼 것  (0) 2016.02.26
python vs ruby  (0) 2016.02.13
ruby vs python  (0) 2016.02.10

ruby vs python

언어/비교2016. 2. 10. 16:35
#Ruby
#2016 02 10
greeting = "Hello world"
for i in 0..greeting.length
puts(greeting[i])
end

puts ('Hello'[0]) #H
puts ('Hello'[1]) #e
puts ('Hello'[2]) #l
puts ('Hello'[3]) #l
puts ('Hello'[4]) #0

puts ('hello'.capitalize) #=> Hello
puts ('hello'.upcase) #=> HELLO
puts ('HELLO'.downcase) #=> hello
puts ('hello'.length) #=> 5

puts (greeting.sub('world', 'kim')) #=> Hello kim
puts (greeting) #=> Hello world
puts ("kim's \"tutorial\"")
# ---> puts("\") error
puts("\\") # \
puts("hello\nworld") #=> n -> new line
puts("hello\tworld") #=> hello world
puts("\a")

puts('hello \nworld') #=> hello \nworld



#python
#2016 02 10
greeting = "hello"
for i in range(0, len(greeting)):
print(greeting[i])

print("hello"[0]) # 'h'
print("hello"[1]) # 'e'
print("hello"[2]) # 'l'
print("hello"[3]) # 'l'
print("hello"[4]) # 'o'

print("hello".capitalize()) # 'Hello'
print("hello".upper()) # 'HELLO'
print("HELLO".lower()) # 'hello'
print(len("hello")) # 5
print("hello".__len__()) # 5
print("hello world".replace('world', 'programming')) #=> 'hello programming'
print("hello".count('l'))
print("kim's \"tutorial\"")

print("hello\nworld")
print("hello\tworld")
print("\a")
print('hello\nworld')


'언어 > 비교' 카테고리의 다른 글

dividen  (0) 2016.03.25
python go [python이 확실히 더 직관적이다.] 루비는 다시 볼 것  (0) 2016.02.26
python vs ruby  (0) 2016.02.13
python vs ruby  (0) 2016.02.13