Answer:
Explanation:
The following is written in Python. It creates the dictionary as requested and prints it out to the output file as requested using the correct format for various shows with the same number of seasons.The output can be seen in the attached picture below.
mydict = {}
with open("file1.txt", "r") as showFile:
for line in showFile:
cleanString = line.strip()
seasons = 0
try:
seasons = int(cleanString)
print(type(seasons))
except:
pass
if seasons != 0:
showName = showFile.readline()
if seasons in mydict:
mydict[seasons].append(showName.strip())
else:
mydict[seasons] = [showName.strip()]
f = open("output.txt", "a")
finalString = ''
for seasons in mydict:
finalString += str(seasons) + ": "
for show in mydict[seasons]:
finalString += show + '; '
f.write(finalString[:-2] + '\n')
finalString = ''
f.close()
Answer:
The solution code is written in Python
- def largerThanN(myList, n):
- output = ""
-
- for x in myList:
- if(x > n):
- output += str(x) + " "
-
- print(output)
-
- l = [5, 12, 11, 4, 56, 32]
- n = 15
- largerThanN(l, n)
Explanation:
Firstly, create a function largerThanN that accepts two arguments, a list (myList) and a number (n) (Line 1).
Next, create a output variable to hold the string of numbers in the list that are greater than the input number n (Line 2).
Create a for loop to traverse through each number in the list and then check if the current x is bigger than n. If so concatenate the x to output string along with a single space " " (Line 4 -6)
After the loop, print the output string (Line 8)
We test the function by using a sample list and n = 15 (Line 10 - 12). The program will display 56 32 .
Answer:
import java.util.Scanner;
public class num6 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int product=0;
do{
System.out.println("Enter a number");
int num = in.nextInt();
product = num*10;
System.out.println("The product is " + product);
}while (product<100);
}
}
Explanation:
In the Java program above, The user will be prompted to enter a number.
The number is multiplied by 10 and assigned to a variable called product.
A do....while loop has been implemented to check the variable product
As long as this variable is less than 10, the user will be prompted to enter another number.
April 15th of each annual year