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

Forum Jump: 

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

Reply
 
Thread Tools
post #21 of 51 (permalink) Old 11-12-2017, 03:51 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,832
Rep: 18 (Unique: 17)
Why wouldn't you just put > instead of >=? Since it 40 * 2 will always and forever be greater than -4. Why even bother with the "or"?

"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 #22 of 51 (permalink) Old 11-12-2017, 06:27 PM
 
 
gonX's Avatar
 
Join Date: May 2006
Location: Odense, Denmark
Posts: 29,522
With that reasoning why not just replace the entire line with 'bool_four = True'? In this case I'd wager it's just a question of preference.

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 #23 of 51 (permalink) Old 11-13-2017, 06:54 AM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,832
Rep: 18 (Unique: 17)
I've been asking that same question all throughout the lessons lol. I've come to the conclusion that they're just doing a lot of seemingly unnecessary stuff, in order to teach people. It is helping me brush up on highschool math though.

"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 #24 of 51 (permalink) Old 11-13-2017, 10:22 AM
 
 
gonX's Avatar
 
Join Date: May 2006
Location: Odense, Denmark
Posts: 29,522
I've personally never been a fan of the academic approach of lots of theory, but rather some actual usable code.

I use codewars.com to practice my code. Haven't tried Python specifically, but their C# challenges are great.

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 #25 of 51 (permalink) Old 11-15-2017, 08:34 AM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,832
Rep: 18 (Unique: 17)
Yeah it makes it difficult to understand what they actually want in some cases. I often find that they could have worded it better, or even just given a slightly more long winded explanation. And that would have helped. But of course they have to take into account that it will vary from person to person. One person will be confused, while another will understand it perfectly. Then on the next exorcise, those people swap places. Guess you just have to sort of have faith that they know what they're doing, and they know how to teach. And that it will all make sense eventually.

"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 #26 of 51 (permalink) Old 12-12-2017, 10:26 AM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,832
Rep: 18 (Unique: 17)
New python question. I'd like to hear what you guys have to say on this:

Why does elif exist?

The way I understand it, it goes like this: if (some function), do this.

Else, do this. Why would elif be needed? Wouldn't it make more sense to just be able to use an infinite number of elses?

"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 #27 of 51 (permalink) Old 12-12-2017, 10:31 AM
Retired Staff
 
herkalurk's Avatar
 
Join Date: May 2010
Location: Portland, OR
Posts: 2,039
Rep: 69 (Unique: 58)
Quote:
Originally Posted by PhotonFanatic View Post

New python question. I'd like to hear what you guys have to say on this:

Why does elif exist?

The way I understand it, it goes like this: if (some function), do this.

Else, do this. Why would elif be needed? Wouldn't it make more sense to just be able to use an infinite number of elses?
Code:
if [ hour < 12 ]
then
   echo "good morning"
else if [ hour > 12 && hour < 18 ]
then
   echo "good afternoon"
else
   echo "good evening"
fi

Like the above code, sometimes you need more decision making. I made a workflow for a job and I had 5 else if statements in a row and finally an else. The reason was I needed to make sure that my final decision (the else) had passed a bunch of safety checks. If all of the else if statements returned false then I knew it was safe to proceed with the else, otherwise the else if statement would return a failure error.



herkalurk is offline  
post #28 of 51 (permalink) Old 12-12-2017, 11:33 PM
New to Overclock.net
 
ltpdttcdft's Avatar
 
Join Date: Jun 2013
Posts: 575
Rep: 35 (Unique: 30)
Nested ifs can become hard to keep track of once you go several levels deep. Good enough reason for things like elif and case to exist.



ltpdttcdft is offline  
post #29 of 51 (permalink) Old 12-13-2017, 12:56 PM
Retired Staff
 
herkalurk's Avatar
 
Join Date: May 2010
Location: Portland, OR
Posts: 2,039
Rep: 69 (Unique: 58)
Code:
        if [ `grep -c "^#dateext" ${ROTATE}` -eq 1 ]
        then
                sed -i 's/^#dateext/dateext/g' ${ROTATE}
                echo "Uncommented dateext"
                SUCCESS[${#SUCCESS[*]}]="Log date extnesions uncommented in config\n"
        elif [ `grep -c "^dateext" ${ROTATE}` -eq 1 ]
        then
                echo "dateext already enabled"
                SKIP[${#SKIP[*]}]="Log date extensions already enabled in config\n"
        elif [ `grep -c "^dateext" ${ROTATE}` -eq 0 ]
        then
                sed -i "s/compress/compress\n\ndateext/g" ${ROTATE}
                echo "Added dateext"
                SUCCESS[${#SUCCESS[*]}]="Log date extensions setting added to config\n"
        else
                echo "Unsure of what to do? dateext isn't normal"
                FAIL[${#FAIL[*]}]="Log date extnesions settings aren't normal, please fix manually\n"
        fi

Here's another example I found in my scripts. It's part of a script to setup a RHEL box and configure the logrotate settings. The first if checks to see if dateext is commented, then uncomment, then 2nd it it's already uncommented the log the fact we skipped it, then 3rd we didn't find it, so we add it, and finally a failure message.



herkalurk is offline  
post #30 of 51 (permalink) Old 12-25-2017, 04:34 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,832
Rep: 18 (Unique: 17)
Thanks once again for the help everyone. Much appreciated.

Now I ask

Is raw_input always preceded by a variable? As in, the raw_input function will not work, unless a variable is assigned first?

"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  
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