Trong hướng dẫn Python này. Tôi sẽ chỉ cho bạn cách tìm số thứ hai AMoung ba số với hai cách thay thế. Chấp nhận ba số từ người dùng và hiển thị số lớn thứ hai trong Python. Cách 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Chương trình #Python để tìm ra số lượng lớn thứ hai trong ba số đã cho num1 = int [input ["nhập số đầu tiên:"]]=int[input["Enter first number :"]] num2 = int [input ["nhập số thứ hai:"]]=int[input["Enter second number :"]] num3 = int [input ["nhập số thứ ba:"]]
=int[input["Enter third number :"]] ifnum1> num2 andnum1> num3:num1>num2 andnum1>num3: ifnum2>num3:ifnum2>num3:
& nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn thứ hai là", num2]print["The second largest number is",num2] else:else: & nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn nhất là", num3]print["The largest number is",num3] Elifnum2> num1 andnum2> num3:num2>num1
andnum2>num3: ifnum1>num3:ifnum1>num3: & nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn thứ hai là", num1]print["The second largest number is",num1] else:else:
& nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn thứ hai là", num3]print["The second largest number is",num3] else:: ifnum1>num2:ifnum1>num2: & nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn thứ hai là", num1]print["The second largest number
is",num1] else:else: & nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn thứ hai là", num2]print["The second largest number is",num2]
Output:
Enterfirstnumber:10firstnumber:10 Entersecondnumber:20secondnumber:20 Enterthirdnumber:30thirdnumber:30 Thesecondlargestnumberis20secondlargestnumberis20 |
& nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn nhất là", num3]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | Chương trình #Python để tìm ra số lượng lớn thứ hai trong ba số đã cho num1 = int [input ["nhập số đầu tiên:"]]=int[input["Enter first number :"]] num2 = int [input ["nhập số thứ hai:"]]=int[input["Enter second number :"]] num3 = int [input ["nhập số thứ ba:"]] =int[input["Enter third number :"]] largest=0=0 smallest=0=0 ifnum1> num2 andnum1> num3: ifnum1> num2 andnum1> num3:num1>num2 andnum1> num3: largest=num1largest=num1 Elifnum2> num1 andnum2> num3:num2>num1 andnum2>num3: largest=num2largest=num2 else:: largest=num3largest=num3 & nbsp; & nbsp; & nbsp; & nbsp; in ["số lớn thứ hai là", num1] ifnum1num1 = c]?[[b> = c]? B: c]: [[b> = c]? [[a> = c]?int x = [a >= b && a >= c] ? [[b >= c] ? b : c] : [[b >= c] ? [[a >= c] ? Chủ Đề |