Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to write a function named listsearch, which accepts a single parameter, but I don't know how.

The two lists (facts and factsK) must remain separate.

I was trying to move both print statements into separate functions and just calling it at the end because the code requires two calls, I can't figure out how to proceed

facts = ["Hitler invaded Poland in 1939 which drove Great Britain and France to Declare war",
         "Germany occupied Norway and Denmark and started the 'Blitzkrieg' against Belgium and the Netherlands",
         "Following the attack on Pearl Harbor, the USA declares war against Japanese",
         "USA begins raiding Japanese islands and bombing the mainland military targets",
         "Allies invade Sicily and put Mussolini out of power",
         "The Allies conduct the largest amphibious invasion ever at the Battle of Normandy where over  155,000 allied troops fought through the Atlantic wall to create a new front in France",
         "May 8th 1945 Germany surrendered after the Soviets invaded Berlin"]

factsK = ["The deadliest battle in the War, Germany and its allies fought the Soviets for the city with extreme close quarters combat and direct air raids on civilians", 
          "Was a German military tactic calculated to create psychological shock and resultant disorganization in enemy forces through the employment of surprise, speed, and superiority",
          "The allies were losing the battle of France and were pushed to the port of Dunkirk by the Germans. The Germans halted their push for three days which allowed the allies to organize a retreat, more than 330,000 Allied troops were rescued",
          "In 1941, Just before that Sunday morning, hundreds of Japanese fighter planes descended on the base, where they managed to destroy or damage nearly 20 American naval vessels, 300 airplanes, and 2,400 Americans, Japan was hoping to cripple the American fleet before they entered the war. The USA declared war the day after",
          "Codenamed Operation Overlord, the battle began on June 6, 1944, also known as D-Day, when some 155,000 American, British and Canadian forces landed on five beaches along a 50 mile stretch of the heavily fortified coast of France’s Normandy region, creating a second front.D-Day was known as the beginning of the end of the War.",
          "The liberation of Paris occurred in 1944 where French Liberation forces staged an uprising against the Germans while the Americans were quickly approaching. Once the American army arrived in the city the German Garrison commander Dietrich von Choltitz, surrendered to the French allowing them to have the city again",
          "The battle of Berlin occurred in 1945 and was one of the last major offensives in the war. The Soviets successfully encircled the city, The Germans refused to surrender, but the Soviets were too overpowering for the remaining troops. Hitler ended up committing suicide and the remaining German troops were captured or killed. The Nazis officially surrendered a week later on May 9th"]

    User = input("Keyword or date: ")

    Dates = ["1939","1940","1941","1942","1943","1944","1945"]

    Keywords =["Stalingrad","Blitz","Dunkirk","Pearl Harbor","D-Day","Paris","Berlin"]

    for D in Dates:
        if D == User:
     def listSearch ():
         for K in Keywords:
             if K == User:

What I have tried:

I tried moving the def() to define each print statement and call at the end but I cant figure it out.
Updated 22-Apr-22 11:55am
Dave Kreskowiak 22-Apr-22 18:28pm    
Reverted your "Delete delete delete". It's very rude to try and hide your question after it's been answered.

Share this answer
You just need all the search code in your listSearch function. You then call it with the user's input value:
def listSearch(userword: str):
	for D in Dates:
		if D == userword:

	for K in Keywords:
		if K == userword:

User = input("Keyword or date: ")

Note that you should also add some code that prints an error message if the user's input is not found in either table.
Share this answer
Member 15610277 22-Apr-22 16:06pm    
Can you explain what the parameter is? Im not sure how the (userword: str) works.
Richard MacCutchan 23-Apr-22 3:46am    
See 4. More Control Flow Tools — Python 3.10.4 documentation[^]. You should make use of the Python tutorials as they explain everything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900