๐Ÿ‘ฉ‍๐Ÿ’ป/ruby & python

[python & ruby] ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž

ํ•œ๋‚˜ 2020. 3. 17. 20:34

๋ฃจ๋น„์™€ ํŒŒ์ด์ฌ ๋ชจ๋‘ ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž ์ ์šฉ์ด ํฌ๊ฒŒ ๋‹ค๋ฅด์ง€ ์•Š๋‹ค. 

๋ฃจ๋น„์˜ ๊ฒฝ์šฐ :

puts("์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
input = gets.chomp()
real_hannah = "11"
real_jessy = "ab"

if real_hannah == input or real_jessy == input
  puts("Hello!, user")
else
  puts("who are you?")
end

 

์‚ฌ์šฉ์ž๊ฐ€ 11์ด๋‚˜ ab ๋‘˜ ์ค‘ ์–ด๋Š ๊ฒƒ์„ ์ž…๋ ฅํ•˜๋”๋ผ๋„ or๋กœ ๋ฌถ์—ˆ์œผ๋ฏ€๋กœ ์ฐธ์ด ๋œฌ๋‹ค.

 

ํŒŒ์ด์ฌ์˜ ๊ฒฝ์šฐ:

in_str = input("์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.\n")
real_hannah = "11"
real_jessy = "ab"

if real_hannah == in_str or real_jessy == in_str:
    print("Hello! user")
else:
    print("Who are you?")

 


ํ•œ ์‚ฌ์šฉ์ž์—๊ฒŒ์„œ ์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ชจ๋‘ ์ž…๋ ฅ๋ฐ›๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ ๋‹ค๊ณ  ํ•œ๋‹ค๋ฉด, ํŒŒ์ด์ฌ์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด if ๋ฌธ์„ ์ค‘์ฒฉํ•ด ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์จ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค. 

 

input_id = input("์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.\n")
input_pw = input("๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.\n")
real_id = "hannah"
real_pw = "12345"

if real_id == input_id:
    if real_pw == input_pw:
        print("Hello!")
    else:
        print("์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค.")
else:
    print("์ž˜๋ชป๋œ ์•„์ด๋””์ž…๋‹ˆ๋‹ค.")

 

์•„์ด๋””๋ฅผ ์ž˜๋ชป ์ ์—ˆ๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ๋„ ์ž˜๋ชป ์ ์—ˆ์„ ๋•Œ, ๋น„๋ฐ€๋ฒˆํ˜ธ๊นŒ์ง€ ์ž…๋ ฅํ•˜๋Š” ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋œ ํ›„ '์ž˜๋ชป๋œ ์•„์ด๋””์ž…๋‹ˆ๋‹ค'๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค. 

์•„์ด๋””๋ฅผ ๋งž๊ฒŒ ์ž…๋ ฅํ•˜๊ณ  ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ‹€๋ ธ์„ ๋•Œ, '์ž˜๋ชป๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค.'๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค. 

 

๋…ผ๋ฆฌ์—ฐ์‚ฐ์ž and๋ฅผ ์ด์šฉํ•ด ์œ„ ๋‘ ์ฝ”๋“œ๋Š” ๊ฐ๊ฐ ์•„๋ž˜์ฒ˜๋Ÿผ ํ†ตํ•ฉํ•ด์„œ ์ข€ ๋” ๊ฐ„๋žตํ•œ ์ฝ”๋“œ๋กœ ๊ฐœ์„ ๋  ์ˆ˜ ์žˆ๋‹ค. (์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๊ฐœ๋ณ„์ ์œผ๋กœ ํ™•์ธํ•˜๋Š” ์ฝ”๋“œ๋Š” ์•„๋‹˜)

 

๋ฃจ๋น„

 

puts("์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
input_id = gets.chomp()
puts("๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
input_pwd = gets.chomp()

real_id = "hannah"
real_pwd = "12"

if real_id == input_id and real_pwd == input_pwd
    puts("Hello!, user")
else
    puts("๋กœ๊ทธ์ธ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
end

 

ํŒŒ์ด์ฌ

 

input_id = input("์•„์ด๋””๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.\n")
input_pw = input("๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.\n")
real_id = "hannah"
real_pw = "12345"

if real_id == input_id and real_pw == input_pw:
    print("Hello!")
else:
    print("๋กœ๊ทธ์ธ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")