Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Question 1: The following code is meant to find the largest item of a list, but the lines are out of order. The following code is meant to define such a function, but the lines are out of order. In your answer put the line numbers in the correct order and introduce appropriate indentation (indent the line numbers to show how the corresponding lines would be indented in your code). Do not write the entire corrected program in your answer.

1 if number > largest:

2 numbers = [3, 5, 2, 1, 4]

3 print largest

4 largest = number

5 for number in numbers:

6 largest = 0

Question 2 : Describe two different ways to represent a birthday register, i.e. the names of your friends and their birth dates. Assume that none of your friends have the same name, but that it is possible for two or more of them to share the same birthday. Do not represent the date as a string. Show how the following data would be represented in both models.

2/Jan Asimov

3/Jan Tolkien

18/July Mandela

18/July Branson

Question 3: Explain the purpose of the following code:

d = {}

for x in open("data.txt").read().split():

if x not in d:

d[x] = 0

d[x] += 1

Question 4: Consider the following code: 1. signFlag = False

2. evenFlag = False

3. inputstr = raw_input("Enter two numbers: ")

4. num1 = int(inputstr.split(", ")[0])

5. num2 = int(inputstr.split(", ")[1])

6. if num1 < 0 and num2 = 0 and num2 >= 0:

10. sign = 'positive'

11. signFlag = True

12. if num1%2 == 0 and num2%2 == 0:

13. num = 'even'

14. evenFlag = True

15. if num1%2 != 0 and num2%2 != 0:

16. num = 'odd'

17. evenFlag = True

18. if signFlag and evenFlag:

19. print num1, 'and', num2, 'are both', sign, 'and', num

20. elif signFlag:

21. print num1, 'and', num2, 'are both', sign

22. elif evenFlag:

23. print num1, 'and', num2, 'are both', num

24. else:

25. print num1, 'and', num2, 'have nothing in common'

--Assume that the input is "-12, 14". Using the given line numbers in this code (at the far left of the listing) list the order (by writing down the line number order) that the code will be executed.

--What is the output for the input "-12, -14"?

--What is the output for the input "-3, 9"?

--Explain in detail what the program does.

Question 5: Write a function file_length(filename) which takes the name of a file as its only parameter, and returns an integer specifying the number of lines in the file.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92022238
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Programming Language

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As