Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I: WrittenCreate a text file named part 1 . txt that contains the answers to these questions.Convert the following binary numbers into decimal, assuming

Part I: WrittenCreate a text file named part1.txt that contains the answers to these questions.Convert the following binary numbers into decimal, assuming they are unsigned integers. Show the calculation you did to get the decimal value.110110011101011110000000110000000Convert the following binary numbers into decimal, assuming they are two's complement values. Show the calculations you did to get the decimal value.110110011101011110000000110000000Using this number of bits, what are the highest and lowest numbers we can represent with unsigned integers and twos complement?4810Write pseudocode (as described in Section 1.4 of the course guide) describing the procedure of the following guessing game:At the beginning of the program, it chooses a random number between 1 and 100. The user will be asked to guess a number, and told whether the actual number chosen by the computer is higher or lower then their guess. When the user guesses the number, a message will tell them that they have guessed the correct number and the game should end.[Note this isn't the game described in lecture: it's the other way around. Here, the user is guessing, not the computer.]What is the difference between the = operator and the == operator?Part II: ProgrammingFor this assignment, you will write a program dayofyear.py and will ask the user to enter a date and then doing some manipulation of the value.The actual part of the program visible to the user will be quite simple. First, ask the user for the date in the form 2011/05/18(in year/month/day format; this represents May 18,2011).Once that is done, calculate the day of the year (where January 1 is the first day of the year) and display it. When your program runs, it should look like this:Enter a date in the form YYYY/MM/DD: 2000/01/012000/01/01 is day 1 of the year 2000.Here is another example:Enter a date in the form YYYY/MM/DD: 2007/09/052007/09/05 is day 248 of the year 2007.The calculation of the day of year (DOY) is relatively straightforward. If you can determine the DOY of the first day of that month, the answer is a simple addition away.You will need to do some checking of the input to make sure it's in the correct format, but checking every possible error is beyond the scope of this assignment. You will first need to check that the slashes are in the right places, and then that the specified date is a real day.Leap YearsThe difficulty comes in leap years (when there are 29 days in February). The rule for which years are leap years is more complicated than a lot of people realize:Years divisible by 4 are leap years,except, years divisible by 100 are not leap years,except, years divisible by 400 are leap years.If the year is an integer in the variable year, this boolean expression is true for exactly the leap years:year%400==0 or (year%100!=0 and year%4==0)In leap years, the 29th of February is a valid date, and every day after that is one day later in the year.Suggested PlanWrite and test small parts of the program at a time. Test each part (by printing the value of variables and making sure they are as you expect) as you go and make sure it's working before you move on. Doing this will let you concentrate on smaller, more manageable problems. Here is a suggested plan of attack:Get the user input working as required.Check to make sure the fifth and eighth character are a slash. Print out an error message if not.Extract the year, month, and day from the string and convert to integers.Get the output working with the parts you already have: 2007/09/05 is day ??? of the year 2007. You will fill in the ??? later.Create an if/elif block that sets two variables as appropriate to the month (ignoring leap years). You will need to know the number of days in the month, and the DOY of the first day of that month (e.g. March has 31 days, and the first of March is the 60th day of the year).After the if/elif block, use those two variables to calculate the day of the year. Include this in the print statement so the output looks correct (and should be correct, except for leap years).Insert code after the big if/elif block that fixes the value of the two variables as appropriate in leap years.Add checking for invalid dates (month or day invalid).HintsTo create this program, you will need the following aspects of Python that you might not have seen yet:String indexing. If you have a string variable s, you can get at the first character (at the left of the string) with s[0], the second with s[1], and so on.String slicing. To extract the day, month, and year from the user's input, you will need to not only extract individual characters, but larger parts of the string. We don't need to worry about the details; here are some relevant examples run in the Python interactive interpreter:>>> s = "abcd/ef/gh">>> s[0:4]'abcd'>>> s[5:7]'ef'>>> s[8:10]'gh'You will need to convert strings of digits to integers to do the arithmetic.year = int(????)Try to use good variable names and keep your code as readable as possible. There won't be any marks for style in this assignment, but there will be in the future, so you might as well get in the habit.Here are some more examples that you can use to test your code that cover the leap year rules and more:DateDOYNote2011/02/1546non-leap year2011/03/0261non-leap year2012/02/1546leap year, before Feb 292012/03/0262leap year, after Feb 291900/03/0261divisible by 100 rule2000/03/0262divisible by 400 rule2000/01/0222000/06/301822016/07/121942009/12/253593421/04/261162010/12/88invalid date2010/06/31invalid date2011/02/29invalid date2011/13/01invalid date2012/01/00invalid date2012/00/01invalid date

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

=+c) Calculate the lower control limit of the p chart.

Answered: 1 week ago

Question

What is your current position?

Answered: 1 week ago