Why is this correct? Looks to me like it shouldn't work. - Page 2 - Overclock.net - An Overclocking Community

Forum Jump: 

Why is this correct? Looks to me like it shouldn't work.

Reply
 
Thread Tools
post #11 of 51 (permalink) Old 10-26-2017, 10:26 AM
New to Overclock.net
 
czin125's Avatar
 
Join Date: Jul 2007
Posts: 2,299
Rep: 52 (Unique: 47)
Is there any difference if you did either one of these?

meal = 44.50
tax = meal*0.0675
tip = meal*0.1500
total = meal + tax + tip

or

meal = 44.50
tax = 0.0675
tip = 0.1500
total = meal + meal * ( tax + tip ) // 0.0675+0.1500 = 0.2175

czin125 is offline  
Sponsored Links
Advertisement
 
post #12 of 51 (permalink) Old 10-26-2017, 01:53 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,879
Rep: 19 (Unique: 18)
Yeah it finally threw an error when I tried several other variations. But I think its possible that it was because it wasn't what the lesson wanted. I'm seeing that some things that will work, don't really go along with their lesson plans. It would work for a bit, then throw an error. You'd probably have to do the exercises to see what I'm talking about, but sometimes it will let you, and sometimes it just says its the wrong answer and you don't progress.

"Executing execution.exe"
Bang for the buck
(12 items)
CPU
3570k @ 4.6Ghz @1.35v
Motherboard
Gigabyte Z77x UD3H
GPU
evga GTX 970 SSC
RAM
16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28
Hard Drive
Samsung Evo 850
Power Supply
Silverstone 900 watt
Cooling
Thermalright Ultra 120 Extreme
Case
Silverstone Raven (1st edition)
Operating System
Windows 10 Spy Delux
Monitor
Xstar 27" PLS 1440p
Keyboard
Wireless ergonomic
Mouse
Logisys Wireless trackball
▲ hide details ▲
PhotonFanatic is offline  
post #13 of 51 (permalink) Old 10-30-2017, 12:06 AM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,879
Rep: 19 (Unique: 18)
I'm back. So how is 14 correct in this instance? Clearly there are 13 characters in "Norwegian Blue". Yet as you can see, it spits out 14. Is it counting the space between the n, and the B?


"Executing execution.exe"
Bang for the buck
(12 items)
CPU
3570k @ 4.6Ghz @1.35v
Motherboard
Gigabyte Z77x UD3H
GPU
evga GTX 970 SSC
RAM
16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28
Hard Drive
Samsung Evo 850
Power Supply
Silverstone 900 watt
Cooling
Thermalright Ultra 120 Extreme
Case
Silverstone Raven (1st edition)
Operating System
Windows 10 Spy Delux
Monitor
Xstar 27" PLS 1440p
Keyboard
Wireless ergonomic
Mouse
Logisys Wireless trackball
▲ hide details ▲
PhotonFanatic is offline  
Sponsored Links
Advertisement
 
post #14 of 51 (permalink) Old 10-30-2017, 08:24 AM
New to Overclock.net
 
Aulasky's Avatar
 
Join Date: Sep 2014
Location: Leeds, United Kingdom
Posts: 58
Rep: 1 (Unique: 1)
Yes whitespace is a character in a string in python therefore it counts it.

Aulasky is offline  
post #15 of 51 (permalink) Old 10-30-2017, 04:14 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,879
Rep: 19 (Unique: 18)
So any blank space is automatically whitespace? What about completely empty lines? Makes sense that they would be, but I know its best to ask before assuming anything lol

"Executing execution.exe"
Bang for the buck
(12 items)
CPU
3570k @ 4.6Ghz @1.35v
Motherboard
Gigabyte Z77x UD3H
GPU
evga GTX 970 SSC
RAM
16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28
Hard Drive
Samsung Evo 850
Power Supply
Silverstone 900 watt
Cooling
Thermalright Ultra 120 Extreme
Case
Silverstone Raven (1st edition)
Operating System
Windows 10 Spy Delux
Monitor
Xstar 27" PLS 1440p
Keyboard
Wireless ergonomic
Mouse
Logisys Wireless trackball
▲ hide details ▲
PhotonFanatic is offline  
post #16 of 51 (permalink) Old 10-30-2017, 05:38 PM
 
 
gonX's Avatar
 
Join Date: May 2006
Location: Odense, Denmark
Posts: 29,522
Rep: 1157 (Unique: 647)
Quote:
Originally Posted by PhotonFanatic View Post

So any blank space is automatically whitespace? What about completely empty lines? Makes sense that they would be, but I know its best to ask before assuming anything lol

Typically a newline counts as 1 character, but can also count as 2 in some cases: https://en.wikipedia.org/wiki/Newline#Representations - only the first point is relevant here.

What does OCN offer as a site?
What are infractions and warnings?
How to make quality posts
#well
(19 items)
CPU
Intel Core i7 4770k
Motherboard
Gigabyte Z87X-UD4H
GPU
Sapphire RX 580
RAM
2x G.Skill F3-2400C10-8GTX
Hard Drive
Samsung 840 EVO
Optical Drive
Generic DVD±RW Burner
Power Supply
Corsair TX850
Cooling
Noctua NH-D14
Case
Fractal Design Core 2500
Operating System
Arch Linux
Monitor
Dell U2711
Monitor
Samsung SyncMaster 2233
Monitor
LG W2453TQ
Keyboard
Ducky DK9008G2, Cherry MX Blue, Overclock.net Edition
Mouse
Logitech G303
Mouse
Xtrfy GP3 HeatoN
Audio
Beyerdynamic DT-770 80 Ohm
Audio
AntLion ModMic v3
Audio
M-Audio Fast Track USB
▲ hide details ▲


gonX is offline  
post #17 of 51 (permalink) Old 11-06-2017, 12:40 PM
New to Overclock.net
 
Mrzev's Avatar
 
Join Date: Feb 2008
Location: Texas
Posts: 2,258
Rep: 96 (Unique: 76)
With math and order of opperations stuff.... its just easier to just use a lot of parentheses for readability sake. c= a + (B*2) Total = Meal + (Meal * tip) Granted this can be simplified in this case by Total = Meal * Tip+1 but thats just harder to understand whats happening.

DO NOT WORRY ABOUT OPTIMIZED CODE. Nothing needs to be optimized until it actually becomes a problem. I have wasted a ton of time on projects because i was trying to optimize my code early on making it harder to read and the optimizations are very negligible 99% of the time. When you need to optimize , its more likely that you need better logic instead of these little things. SO yeah... make things easy and readable first. If need be, clean it up later.

With counts and stuff, its weird and you need to know which way its going about it. If you do a length, it could start with 0 instead of 1. So, x= [1,2,3] gives x.length = 2. while x.count() = 3 . As they said, spaces and newlines count. I doubt you need to worry about this, but encoding can also come into play where you have single and double byte characters.... not sure what that would effect, but it is something.



Mrzev is offline  
post #18 of 51 (permalink) Old 11-07-2017, 09:31 AM
 
 
gonX's Avatar
 
Join Date: May 2006
Location: Odense, Denmark
Posts: 29,522
Rep: 1157 (Unique: 647)
Quote:
Originally Posted by Mrzev View Post

I doubt you need to worry about this, but encoding can also come into play where you have single and double byte characters.... not sure what that would effect, but it is something.

Emojis come to mind. They will register as 2 characters, flag emojis as 4:

6EUvDAD.png

What does OCN offer as a site?
What are infractions and warnings?
How to make quality posts
#well
(19 items)
CPU
Intel Core i7 4770k
Motherboard
Gigabyte Z87X-UD4H
GPU
Sapphire RX 580
RAM
2x G.Skill F3-2400C10-8GTX
Hard Drive
Samsung 840 EVO
Optical Drive
Generic DVD±RW Burner
Power Supply
Corsair TX850
Cooling
Noctua NH-D14
Case
Fractal Design Core 2500
Operating System
Arch Linux
Monitor
Dell U2711
Monitor
Samsung SyncMaster 2233
Monitor
LG W2453TQ
Keyboard
Ducky DK9008G2, Cherry MX Blue, Overclock.net Edition
Mouse
Logitech G303
Mouse
Xtrfy GP3 HeatoN
Audio
Beyerdynamic DT-770 80 Ohm
Audio
AntLion ModMic v3
Audio
M-Audio Fast Track USB
▲ hide details ▲


gonX is offline  
post #19 of 51 (permalink) Old 11-12-2017, 05:36 AM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,879
Rep: 19 (Unique: 18)
Quote:
Originally Posted by Mrzev View Post

DO NOT WORRY ABOUT OPTIMIZED CODE. Nothing needs to be optimized until it actually becomes a problem.

Believe it or not that actually takes a load off my mind, even as a newbie to programming. I was always thinking about how it could be done better, if that was even important, etc. I was wondering just how "strict" it was going to be about having everything perfect.

Next problem. Well its not really a problem, but to me its something that doesn't make sense. Here is part of a python exorcise from codeacademy:



The answer was True. But how can that be true, when you have "Is greater than OR = to". Its the or that I have a problem with. Or = to? No. It is not = to -4. But if you say >=, you're saying it could be. But it never could be, because 40 ** 2 can never be = to -4. So how can you say that its True?

"Executing execution.exe"
Bang for the buck
(12 items)
CPU
3570k @ 4.6Ghz @1.35v
Motherboard
Gigabyte Z77x UD3H
GPU
evga GTX 970 SSC
RAM
16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28
Hard Drive
Samsung Evo 850
Power Supply
Silverstone 900 watt
Cooling
Thermalright Ultra 120 Extreme
Case
Silverstone Raven (1st edition)
Operating System
Windows 10 Spy Delux
Monitor
Xstar 27" PLS 1440p
Keyboard
Wireless ergonomic
Mouse
Logisys Wireless trackball
▲ hide details ▲
PhotonFanatic is offline  
post #20 of 51 (permalink) Old 11-12-2017, 07:17 AM
 
 
gonX's Avatar
 
Join Date: May 2006
Location: Odense, Denmark
Posts: 29,522
Rep: 1157 (Unique: 647)
Quote:
Originally Posted by PhotonFanatic View Post



The answer was True. But how can that be true, when you have "Is greater than OR = to". Its the or that I have a problem with. Or = to? No. It is not = to -4. But if you say >=, you're saying it could be. But it never could be, because 40 ** 2 can never be = to -4. So how can you say that its True?


>= means greater than or equal to. So when you write that line, you imply 'is (40 times 4) greater than or equal to (-4)?' in which case it's true. If you remove the equals-to sign you should still get true.

What does OCN offer as a site?
What are infractions and warnings?
How to make quality posts
#well
(19 items)
CPU
Intel Core i7 4770k
Motherboard
Gigabyte Z87X-UD4H
GPU
Sapphire RX 580
RAM
2x G.Skill F3-2400C10-8GTX
Hard Drive
Samsung 840 EVO
Optical Drive
Generic DVD±RW Burner
Power Supply
Corsair TX850
Cooling
Noctua NH-D14
Case
Fractal Design Core 2500
Operating System
Arch Linux
Monitor
Dell U2711
Monitor
Samsung SyncMaster 2233
Monitor
LG W2453TQ
Keyboard
Ducky DK9008G2, Cherry MX Blue, Overclock.net Edition
Mouse
Logitech G303
Mouse
Xtrfy GP3 HeatoN
Audio
Beyerdynamic DT-770 80 Ohm
Audio
AntLion ModMic v3
Audio
M-Audio Fast Track USB
▲ hide details ▲


gonX is offline  
Reply

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off