Jump to content

Wikipedia:Reference desk/Archives/Computing/2020 November 19

From Wikipedia, the free encyclopedia
Computing desk
< November 18 << Oct | November | Dec >> Current desk >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


November 19

[edit]

What is wrong with this code?

[edit]

I'm looking at the instructions for "Part A: House Hunting" here:

https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/assignments/MIT6_0001F16_ps1.pdf

Here is my code so far, but it doesn't actually appear to yield the right results:

   annual_salary = int(input("What is your starting annual salary?: "))
   portion_saved = float(input("What portion of your salary do you want \
   to be saved?: "))
   total_cost = int(input("What is the cost of your dream house?: "))
   current_savings = 0
   month_num = 0
   while current_savings < total_cost:
       current_savings = current_savings * 1+(0.04/12)
       current_savings += (annual_salary * portion_saved)/12
       month_num += 1
   print("Number of months:",month_num)"

What am I doing wrong here? Futurist110 (talk) 04:05, 19 November 2020 (UTC)[reply]

What results do you get and what results are you expecting? RudolfRed (talk) 05:01, 19 November 2020 (UTC)[reply]
   (Inputs:)
   What is your starting annual salary?: 120000
   What portion of your salary do you want to be saved?: .10
   What is the cost of your dream house?: 1000000
   (Output:)
   Number of months: 1000
Apparently the number of months is supposed to be 183 (as opposed to 1000) here, based on "Test Case 1" in the pdf in my OP here. Futurist110 (talk) 05:42, 19 November 2020 (UTC)[reply]
How do you enter the portion of your salary? The code seems to be expecting a number less than 1, e.g. 0.5 to save half your salary. If you are entering a percentage the results will probably not be what you expect.-gadfium 05:19, 19 November 2020 (UTC)[reply]
I enter it as a float/decimal. So, instead of 50%, I type in 0.5; instead of 20%, I type in 0.2. And so on. Futurist110 (talk) 05:42, 19 November 2020 (UTC)[reply]
I don't see where the sample solution gets 183 months. The interest rate is so low it doesn't affect the result. However, your program doesn't conform in one major way I can see. I suggest you re-read point 2 in the list of assumptions.-gadfium 06:01, 19 November 2020 (UTC)[reply]
It says 183 months in the middle of page 2 in the pdf in my OP (original post) here. Futurist110 (talk) 08:45, 19 November 2020 (UTC)[reply]
Spotted it. You have an error in your calculation of interest rate. Your brackets are wrong.-gadfium 06:12, 19 November 2020 (UTC)[reply]
So, what is the correct way to put the brackets? Futurist110 (talk) 08:45, 19 November 2020 (UTC)[reply]
Without trying to understand the code, I notice that current_savings * 1+(0.04/12) is equivalent to current_savings + (0.04/12), since multiplication takes precedence over addition ("My Dear Aunt Sally"), and current_savings * 1 = current_savings. So presumably the intention is current_savings * (1+(0.04/12)).  --Lambiam 14:32, 19 November 2020 (UTC)[reply]
This still gives me 441 months as opposed to 183 months, though. Futurist110 (talk) 19:49, 19 November 2020 (UTC)[reply]
Check that the 10% portion of your salary is correct. I do get exactly 183 months for a different portion value — GhostInTheMachine talk to me 20:05, 19 November 2020 (UTC)[reply]
You're not supposed to be saving the full purchase price of the house, only the deposit. As I said above, you need to re-read point 2 in the list of assumptions.-gadfium 21:44, 19 November 2020 (UTC)[reply]
I got it; thank you very much! So, the correct code for this exercise is:
   annual_salary = int(input("What is your starting annual salary?: "))
   portion_saved = float(input("What portion of your salary do you want \
   to be saved?: "))
   total_cost = int(input("What is the cost of your dream house?: "))
   current_savings = 0
   month_num = 0
   down_payment = total_cost*0.25
   while current_savings < down_payment:
       current_savings = current_savings * (1 + (0.04 /12))
       current_savings += (annual_salary * portion_saved)/12
       month_num += 1
   print("Number of months:",month_num)
Interestingly enough, this code successfully works with both of the inputs in the PDF in my OP here, producing outputs of 183 months and 105 months (just like in the PDF in my OP here), respectively. Futurist110 (talk) 04:31, 21 November 2020 (UTC)[reply]
Resolved

Oculus Quest 2 without PC

[edit]

I don't have a PC, only a phone. Commercials for the Oculus Quest 2 make it appear that you don't need a PC to play games, but people I've asked about it say that the game runs in Windows and displays in the Oculus. Reading the article here, there is no mention that a PC is required. I just don't want to waste money buying an Oculus only to find out that I can't play any games on it, so I'm trying to see if I can play games directly on the Oculus or do I need to buy a PC (which I don't want) also? 97.82.165.112 (talk) 21:58, 19 November 2020 (UTC)[reply]

As our article mentions, the Oculus Quest 2, like the Oculus Quest after updates, can play games purchased from the Oculus store designed for its internal Android based OS. It can also stream normal PC VR games purchased from anywhere over USB (or WiFi albeit this uses third part apps so isn't an official solution albeit these apps can be sold on the official Oculus store). You may be able to sideload apps [1] but that is quite far from officially supported. Whatever the case, you need a Facebook account. Do note that the Quest and Quest 2 are different from Oculus Rift and Oculus Rift S which were for connecting to a PC only. Actually they are more similar to the Oculus Go in some ways except that never officially supported connecting to a PC (although the Quest didn't at launch either) and was also only 3DOF. So if someone is talking about an Oculus, it depends what they mean. But also, since Oculus has abandoned the Rift line, the Quests are the only Oculus options for PC gaming, and despite the Facebook account controversy,the price of the Quest 2 makes it an attractive proposition for what you get. Therefore for a lot of people, all the they plan to use it for is PC gaming. Nil Einne (talk) 08:50, 20 November 2020 (UTC)[reply]