Bagaimana Anda memberi tahu pengguna jika waktu penyelesaian tertentu sama dengan catatan yang merupakan konstanta. Contohnya adalah "John" memiliki waktu 9,76 yang kurang dari rekor dunia saat ini, kemudian perintah cetak akan memberi tahu pengguna bahwa seorang atlet telah memenuhi rekor dunia. Penjelasan tentang temuan Anda akan sangat membantu.

import time
datasets= []
world_record = int(9.76)


for i in range(0, 8):
    print("Inputting Data for Lane", i)
    gender = str(input("Is the athlete male or female ")) 
    athlete = str(input("What is the athletes name "))
    finishTime = float(input("What was the finishing time "))
    dataset = [gender, athlete, finishTime]
    datasets.append(dataset)
    if finishTime == float("10"):
        print("A world record has been reached")

print("{0:<10}{1:<10}{2:<15}".format("Gender","Athlete","Finish time"))

ds = sorted(datasets, key=lambda x:x[2], reverse=False)

for s in ds:
    time.sleep(1)
    print("{0:<10}{1:<10}{2:<15}".format(s[0], s[1], s[2]))
-1
Mohamed Ismail 3 Mei 2018, 23:15

1 menjawab

Jawaban Terbaik

world_record = int(9.76) dibulatkan ke bawah menjadi 9, pertahankan sebagai world_record = 9.76

Kemudian periksa apakah waktu selesai kurang dari catatan

for i in range(0, 8):
    print("Inputting Data for Lane", i)
    gender = str(input("Is the athlete male or female ")) 
    athlete = str(input("What is the athletes name "))
    finishTime = float(input("What was the finishing time "))
    dataset = [gender, athlete, finishTime]
    datasets.append(dataset)
    #check if the world record has been met
    if finishTime == world_record:
        print("A world record has been met")
    elif finishTime > world_record:
        print("A world record has been beaten")
        print("the new world record is {}".format(s[2]))
        world_record = finishTime 

ATAU

for s in ds:
    time.sleep(1)
    print("{0:<10}{1:<10}{2:<15}".format(s[0], s[1], s[2]))
    if finishTime == world_record:
        print("A world record has been met")
    elif finishTime > world_record:
        print("A world record has been beaten")
        print("the new world record is {}".format(s[2]))
        world_record = finishTime 

Dalam kedua kasus, saya berasumsi Anda ingin memperbarui world_record jika tidak demikian, hilangkan world_record = finishTime

0
ktzr 3 Mei 2018, 21:53