A farmers takes chicken and duck eggs in ‘n’ baskets. In two baskets he has got duck eggs and rest of the bags he has chicken eggs. Number of eggs in each basket is distinct. He tells that number of chicken eggs is twice as that of number of duck eggs. Given the name of the ‘n’ baskets and number of eggs in them, write a code to print the name of baskets with duck eggs and name of basket with chicken eggs. If there can be more than one combination in which duck eggs can be there, consider the first basket name which comes first in the input orderInput FormatFirst line contains the number of baskets, nNext ‘n’ lines contain the name of the baskets and the number of eggs in themOutput FormatPrint name of baskets with duck eggs separated by a space in the first linePrint name of baskets with chicken eggs separated by a space in the next linePrint the name of the baskets in the order of their input and there is no space at the end of the linesExample1Input5B1 5B2 12B3 14B4 23B5 6OutputB3 B5B1 B2 B4Theme:LanguageFont size:12345678910111213141516171819n = int(input())duck_baskets = []chicken_baskets = []for _ in range(n): basket_name, eggs_count = input().split() eggs_count = int(eggs_count) if eggs_count % 2 == 0: duck_baskets.append(basket_name) else: chicken_baskets.append(basket_name)print(' '.join(duck_baskets))print(' '.join(chicken_baskets))20Use custom I/ORun CodeSave CodePause TestStatus:Input5B1 5B2 12B3 14B4 23B5 6Expected outputB3 B5B1 B2 B4Your Program OutputB2 B3 B5B1 B4
Question
A farmers takes chicken and duck eggs in ‘n’ baskets. In two baskets he has got duck eggs and rest of the bags he has chicken eggs. Number of eggs in each basket is distinct. He tells that number of chicken eggs is twice as that of number of duck eggs. Given the name of the ‘n’ baskets and number of eggs in them, write a code to print the name of baskets with duck eggs and name of basket with chicken eggs. If there can be more than one combination in which duck eggs can be there, consider the first basket name which comes first in the input orderInput FormatFirst line contains the number of baskets, nNext ‘n’ lines contain the name of the baskets and the number of eggs in themOutput FormatPrint name of baskets with duck eggs separated by a space in the first linePrint name of baskets with chicken eggs separated by a space in the next linePrint the name of the baskets in the order of their input and there is no space at the end of the linesExample1Input5B1 5B2 12B3 14B4 23B5 6OutputB3 B5B1 B2 B4Theme:LanguageFont size:12345678910111213141516171819n = int(input())duck_baskets = []chicken_baskets = []for _ in range(n): basket_name, eggs_count = input().split() eggs_count = int(eggs_count) if eggs_count % 2 == 0: duck_baskets.append(basket_name) else: chicken_baskets.append(basket_name)print(' '.join(duck_baskets))print(' '.join(chicken_baskets))20Use custom I/ORun CodeSave CodePause TestStatus:Input5B1 5B2 12B3 14B4 23B5 6Expected outputB3 B5B1 B2 B4Your Program OutputB2 B3 B5B1 B4
Solution
To solve this problem, we can use the following steps:
- Read the number of baskets, n, from the input.
- Create two empty lists: duck_baskets and chicken_baskets.
- Use a loop to iterate n times: a. Read the name of the basket and the number of eggs in it from the input. b. Convert the number of eggs to an integer. c. Check if the number of eggs is divisible by 2 (i.e., if it is even). d. If it is divisible by 2, add the basket name to the duck_baskets list. e. If it is not divisible by 2, add the basket name to the chicken_baskets list.
- Print the names of the baskets with duck eggs, separated by a space, using the join() function.
- Print the names of the baskets with chicken eggs, separated by a space, using the join() function.
- The order of the baskets should be maintained, so print the names of the baskets in the order they were inputted.
Here is the code that implements these steps:
n = int(input())
duck_baskets = []
chicken_baskets = []
for _ in range(n):
basket_name, eggs_count = input().split()
eggs_count = int(eggs_count)
if eggs_count % 2 == 0:
duck_baskets.append(basket_name)
else:
chicken_baskets.append(basket_name)
print(' '.join(duck_baskets))
print(' '.join(chicken_baskets))
When you run this code with the given example input, it should produce the expected output:
B3 B5
B1 B2 B4
Similar Questions
There are N cows living in a cowshed, they all are standing in a line numbered form 1 to N in ascending order. The farmer is in funny mood so he made his mind to do something different, he decides to clean K cows from front and K cows from last and so on. A cow whose name is bessy trying to figure out last turn to get clean will belong to which number of cow, she needs your help to find this.Input Format :Input contains two lines , first line of input contains t - Number of test cases.Next t lines will contains two integers N and K - Number of cows and number of cows farmer is selecting from front and end.Output Format :Print the position of cow for every test case in a new line who will get the last turn.Example:Input:29 325 7Output:615Constraints:1. 1 <= T <= 102. 1 <= K<= N <= 10^5
Problem StatementIn a computer science class, students are assigned unique identification letters based on their seating arrangement. Each student has a specific letter, and you are tasked with creating a program to sort these letters in ascending order using the bubble sort algorithm. The sorting should be based on their ASCII values. Input the total number of students and their assigned letters, then display the sorted list, allowing the students to easily identify their seating order.Input format :The first line of input consists of an integer N, representing the total number of students.The second line consists of N space-separated characters, each representing the unique identification letter assigned to a student.Output format :The output prints the sorted list of identification letters based on their ASCII values.Refer to the sample output for formatting specifications.Code constraints :1 ≤ N ≤ 15Each identification letter is a valid ASCII character.The input characters are case-sensitive.Sample test cases :Input 1 :5a y h j oOutput 1 :a h j o y Input 2 :7Q G Y O M N BOutput 2 :B G M N O Q Y Input 3 :8a e T V z X h KOutput 3 :K T V X a e h z
Mai is arranging 12 cans of food in a row on a shelf. She has 5 cans of peas, 1 can of corn, and 6 cans of beets. In how many distinct orders can the cans be arranged if two cans of the same food are considered identical (not distinct)?
Single File Programming QuestionProblem StatementEmma, a computer science student, is organizing a list of names for a project. She needs a program to input a set of names and arrange them in alphabetical order. She wants to write a program that takes the number of names (n) as input and then receives n names. The program should then arrange the names in alphabetical order and print the sorted list.Emma approached you for help, and you are tasked with creating a program to assist her in achieving this.Input format :The first line consists of an integer N, representing the number of names.The next N lines of input consist of a string in each line, representing the names.Output format :The output displays strings, representing the sorted names in alphabetical order, separated by a line.Refer to the sample outputs for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:2 ≤ N ≤ 103 ≤ Length of each name ≤ 14Sample test cases :Input 1 :5KarthickRamKumarUmaSeethaOutput 1 :KarthickKumarRamSeethaUmaInput 2 :8KlausCatherineeeTylerDamonElenaStefanBonnieElijahOutput 2 :BonnieCatherineeeDamonElenaElijahKlausStefanTylerInput 3 :10WilliamOliviaJamesEmmaLiamAvaBenjaminSophiaMiaShakespeareOutput 3 :AvaBenjaminEmmaJamesLiamMiaOliviaShakespeareSophiaWilliamInput 4 :2EveCharliePuthOutput 4 :CharliePuthEve
Isabel is arranging 11 cans of food in a row on a shelf. She has 7 cans of carrots, 3 cans of beans, and 1 can of beets. In how many distinct orders can the cans be arranged if two cans of the same food are considered identical (not distinct)?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.