2016-11-06 4 views
0

3つの数字を読み取り、それらをpythonで昇順に出力するアルゴリズムを書くにはどうすればいいですか?これが私が今まで試したことを助けてください、皆さん、ありがとう、私はあなたに助けてくれることを願っています。これはPythonを使用していて、私はプログラミングに慣れていません。私は昇順で言う部分をどうやって行うのか分からない。3つの数字を読み取り、それらを昇順に並べ替えるアルゴリズムを書くにはどうすればいいですか?

one = float(input("Please input a number : ")) 
two = float(input("Please input a second number : ")) 
three = float(input("Please input a third number : ")) 

if one > two and three: 
    print("")* 
+0

'sorted([one、two、three]) ' – idjaw

+0

数字は小さい順に並べると昇順になると言われます。例えば。図5、図9、図13、図17、および図21は、昇順に配置されている。 [from www.mathsteacher.com.au](http://www.mathsteacher.com.au/year7/ch02_power/06_asc/asc.htm) 101のプログラミングコースに参加している場合は、問題は条件付き。 'if ... else'ステートメントをチェックする必要があります。 [このページを確認](http://www.openbookproject.net/books/bpp4awd/ch04.html) –

+0

@idjawあなたはそれを行う方法を説明できますか?私はそれを理解していません – david

答えて

0

あなたは)(ソート使用することができますが、最初にあなたが持っているこれにしようと、リスト内の番号を保存します。

nums = [] 
one = nums.append(float(input("Please input a number : "))) 
two = nums.append(float(input("Please input a second number : "))) 
three = nums.append(float(input("Please input a third number : "))) 
for num in sorted(nums): 
    print (num) 

sorted() - Python Doc

ifとelse文を使用する必要がある場合は、すべての組み合わせで入力番号について考えて、これを評価する必要があります。

one = float(input("Please input a number : ")) 
two = float(input("Please input a second number : ")) 
three = float(input("Please input a third number : ")) 

if one < two and three < two: 
    if one > three: 
     print(three, one, two) 
    else: 
     print(one, three, two) 
elif one < three and two < three: 
    if one > two: 
     print(two, one, three) 
    else: 
     print(one, two, three)   
elif two < one and three < one: 
    if three > two: 
     print(two, three, one) 
    else: 
     print(three, two, one) 
else: 
    print(one, two, three) 
+0

私が投稿した他のソリューションをチェックすると、ifとelseを使うことができます – kip

0

あなたのコードに基づいて、次のコードは、数字1と2を昇順で順番に印刷します。 3つの要素のコードを完成させることをお勧めします。あなたの移動

one = float(input("Please input a number : ")) 
two = float(input("Please input a second number : ")) 
three = float(input("Please input a third number : ")) 

if one < two: 
    print(one, two) 
else: 
    print(two, one) 

...

+0

私はどのように3つの数字でそれを行うのですか? – david

関連する問題