Trying to solve too young to ride | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Trying to solve too young to ride

The carousel is designed for 3 people who are each at least 16 years old. You are given a program that takes all 3 passengers' ages as inputs and inserts them in a list. Complete the program so that if it finds a value less than 16, it breaks the loop and outputs "Too young!". If the age requirement is satisfied, the program outputs "Get ready!". Sample Input 18 26 19 Sample Output Get ready! Here is what i tried but it did not work ages = [] i = 0 while i<3: age = int(input()) ages.append(age) i+=1 if ages <16: print("Too young") else: print("Get ready!")

19th Apr 2021, 9:25 AM
Simisola Osinowo
Simisola Osinowo - avatar
11 Answers
+ 8
Simisola Osinowo i I would like to recommend solution such as: ages = [] i = 0 y = 1 while i<3: rider_age = int(input()) if rider_age <16: y = 0 break else: ages.append(rider_age) i+=1 #print(ages) if y>0: print("Get ready!") else: print("Too young!")
20th Apr 2021, 2:10 PM
Aditya
Aditya - avatar
+ 2
You don't need the list. Just make a loop that runs a max of 3 times. Before the loop set a variable with the value of the "Get ready!" string. In the loop get the input and convert to int, then compare to 16. If less than 16 set the string variable to the "Too young" string and break from the loop. After the loop output the string variable.
19th Apr 2021, 9:38 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int number = 3; while(number>=0) { Console.WriteLine(number); number--; } } } } // Try not to follow me
22nd Aug 2022, 3:05 AM
Abdul Bari Rahmani
Abdul Bari Rahmani - avatar
0
Aditya this is my attempt ages = [] i = 0 while i<3: age = int(input()) ages.append(age) i+=1 if ages <16: print("Too young") else: print("Get ready!")
19th Apr 2021, 3:33 PM
Simisola Osinowo
Simisola Osinowo - avatar
0
ages = [] i = 0 while i<3: age = int(input()) if age<16: print("Too young!") break else: ages.append(age) i+=1 if i==3: print("Get ready!")
25th Apr 2022, 3:42 AM
Shubhang
0
ages = [] i = 0 while i<3: age = int(input()) if age >= 16: ages.append(age) i+=1 else: print("Too young!") break else: print("Get ready!")
8th Nov 2022, 7:22 PM
Hebert Aranda
- 1
Show your attempt bro
19th Apr 2021, 9:26 AM
Aditya
Aditya - avatar
- 1
Ajith it did not work
19th Apr 2021, 3:36 PM
Simisola Osinowo
Simisola Osinowo - avatar
- 1
ages = [] i = 0 while i < 3: age = int(input()) ages.append(age) i += 1 for i in ages: if i < 16: print(“Too young!”) else: print(“Get ready!”)
9th Sep 2021, 7:49 AM
Khomi TAKAYANAGI
Khomi TAKAYANAGI - avatar
- 1
This works: ages = [] i = 0 while i<3: age = int(input()) if age>15: ages.append(age) i+=1 else: print("Too young!") break else: print("Get ready!")
31st Jan 2022, 9:02 AM
Richard Janecz
Richard Janecz - avatar
- 1
namespace SoloLearn { class Program { static void Main(string[] args) { int number = 3; while (number<=3) { Console.WriteLine(number+"\n"); number--; if (number<0){ break; } }
10th Aug 2022, 2:33 PM
abdellali majdoubi
abdellali majdoubi - avatar