파이썬 입력값을 배열에 집어넣기

조회수 1050회
print("***Liquid Limit Test***")
print("[Welcome to CAULab]")
samples = eval(input("Enter the number of test samples...:"))
for i in range(samples):
    print('data', i + 1, '...', (input(":")), float(input(":")))

# Assign lab test data (blowCount, waterContent)
blowCount = np.array([55, 30, 17, 10])
waterContent = np.array([31.28, 36.30, 40.49, 46.03])

사진처럼 blowCound 와 waterContent에 입력한 값을 집어넣게 하고싶은데 어떻게 해야할까요

이미지

1 답변

  • import numpy as np
    
    print("Liquid Limit Test")
    print("[Welcome to CAULab]")
    samples = int(input("1. Enter the number of test samples... : "))
    blowCount, waterContent = [], []
    print('2. Enter the test data : ')
    for i in range(1, samples+1):
        blow, water = input(f'data {i} ... ').split(', ')
        blow = int(blow)
        water = float(water)
        blowCount.append(blow)
        waterContent.append(water)
    blowCount = np.array(blowCount)
    waterContent = np.array(waterContent)
    print(blowCount)
    print(waterContent)
    

    고갱님, 주의할 점이 있습니다.
    test data 입력 시 blowCount와 waterContent 사이를 반드시 , (콤마 띄어쓰기)로 구분해야 합니다.
    감사합니다.

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)