Answered step by step
Verified Expert Solution
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 parttxt 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 valueConvert the following binary numbers into decimal, assuming they are two's complement values. Show the calculations you did to get the decimal valueUsing this number of bits, what are the highest and lowest numbers we can represent with unsigned integers and twos complement?Write pseudocode as described in Section of the course guide describing the procedure of the following guessing game:At the beginning of the program, it chooses a random number between and 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 in yearmonthday format; this represents May Once that is done, calculate the day of the year where January 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 YYYYMMDD: is day of the year Here is another example:Enter a date in the form YYYYMMDD: is day of the year 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 days in February The rule for which years are leap years is more complicated than a lot of people realize:Years divisible by are leap years,except, years divisible by are not leap years,except, years divisible by are leap years.If the year is an integer in the variable year, this boolean expression is true for exactly the leap years:year or year and yearIn leap years, the th 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: is day of the year You will fill in the later.Create an ifelif 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 eg March has days, and the first of March is the th day of the yearAfter the ifelif 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 yearsInsert code after the big ifelif block that fixes the value of the two variables as appropriate in leap years.Add checking for invalid dates month or day invalidHintsTo 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 the second with s and so onString 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 "abcdefgh s:abcd s:ef s:ghYou will need to convert strings of digits to integers to do the arithmetic.year intTry 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:DateDOYNotenonleap yearnonleap yearleap year, before Feb leap year, after Feb divisible by ruledivisible by ruleinvalid dateinvalid dateinvalid dateinvalid dateinvalid dateinvalid date
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started