- 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!")
11 odpowiedzi
+ 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!")
+ 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.
+ 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
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!")
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!")
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!")
- 1
Show your attempt bro
- 1
Ajith it did not work
- 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!”)
- 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!")
- 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;
}
}