Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Why is this correct? Looks to me like it shouldn't work.
New Posts  All Forums:Forum Nav:

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

post #21 of 39
Thread Starter 
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"?
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
post #22 of 39
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.
#well
(18 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H Sapphire RX 580 2x G.Skill F3-2400C10-8GTX 
Hard DriveOptical DriveCoolingOS
Samsung 840 EVO Generic DVD±RW Burner Noctua NH-D14 Windows 10 
MonitorMonitorKeyboardPower
Dell U2711 Samsung SyncMaster 2233 Ducky DK9008 Overclock.net Edition, Cherry MX B... Corsair TX850 
CaseMouseMouse PadAudio
Fractal Design Core 2500 Logitech G303 Xtrfy GP3 HeatoN M-Audio Fast Track USB 
AudioAudio
Beyerdynamic DT-770 80 Ohm AntLion ModMic v3 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics OEM Hard Mounted Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
OCZ Vertex 3 240GB DVD-+RW Arch Linux 1600x900 TN 
  hide details  
Reply
#well
(18 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H Sapphire RX 580 2x G.Skill F3-2400C10-8GTX 
Hard DriveOptical DriveCoolingOS
Samsung 840 EVO Generic DVD±RW Burner Noctua NH-D14 Windows 10 
MonitorMonitorKeyboardPower
Dell U2711 Samsung SyncMaster 2233 Ducky DK9008 Overclock.net Edition, Cherry MX B... Corsair TX850 
CaseMouseMouse PadAudio
Fractal Design Core 2500 Logitech G303 Xtrfy GP3 HeatoN M-Audio Fast Track USB 
AudioAudio
Beyerdynamic DT-770 80 Ohm AntLion ModMic v3 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics OEM Hard Mounted Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
OCZ Vertex 3 240GB DVD-+RW Arch Linux 1600x900 TN 
  hide details  
Reply
post #23 of 39
Thread Starter 
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.
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
post #24 of 39
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.
#well
(18 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H Sapphire RX 580 2x G.Skill F3-2400C10-8GTX 
Hard DriveOptical DriveCoolingOS
Samsung 840 EVO Generic DVD±RW Burner Noctua NH-D14 Windows 10 
MonitorMonitorKeyboardPower
Dell U2711 Samsung SyncMaster 2233 Ducky DK9008 Overclock.net Edition, Cherry MX B... Corsair TX850 
CaseMouseMouse PadAudio
Fractal Design Core 2500 Logitech G303 Xtrfy GP3 HeatoN M-Audio Fast Track USB 
AudioAudio
Beyerdynamic DT-770 80 Ohm AntLion ModMic v3 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics OEM Hard Mounted Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
OCZ Vertex 3 240GB DVD-+RW Arch Linux 1600x900 TN 
  hide details  
Reply
#well
(18 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H Sapphire RX 580 2x G.Skill F3-2400C10-8GTX 
Hard DriveOptical DriveCoolingOS
Samsung 840 EVO Generic DVD±RW Burner Noctua NH-D14 Windows 10 
MonitorMonitorKeyboardPower
Dell U2711 Samsung SyncMaster 2233 Ducky DK9008 Overclock.net Edition, Cherry MX B... Corsair TX850 
CaseMouseMouse PadAudio
Fractal Design Core 2500 Logitech G303 Xtrfy GP3 HeatoN M-Audio Fast Track USB 
AudioAudio
Beyerdynamic DT-770 80 Ohm AntLion ModMic v3 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics OEM Hard Mounted Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
OCZ Vertex 3 240GB DVD-+RW Arch Linux 1600x900 TN 
  hide details  
Reply
post #25 of 39
Thread Starter 
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.
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
post #26 of 39
Thread Starter 
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?
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
post #27 of 39
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.
Edited by herkalurk - 12/12/17 at 10:34am
post #28 of 39
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.
UD7
(8 items)
 
  
CPUMotherboardGraphicsRAM
FX-8300 Gigabyte GA-990FXA-UD7 GTX 1060 G.Skill 4x8GB 
Hard DriveCoolingOSPower
Seagate Momentus Thin 320GB Cryorig H5 Ultimate Lubuntu 16.04 LTS EVGA Supernova 1000G2 
  hide details  
Reply
UD7
(8 items)
 
  
CPUMotherboardGraphicsRAM
FX-8300 Gigabyte GA-990FXA-UD7 GTX 1060 G.Skill 4x8GB 
Hard DriveCoolingOSPower
Seagate Momentus Thin 320GB Cryorig H5 Ultimate Lubuntu 16.04 LTS EVGA Supernova 1000G2 
  hide details  
Reply
post #29 of 39
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.
post #30 of 39
Thread Starter 
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?
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
Bang for the buck
(12 items)
 
  
CPUMotherboardGraphicsRAM
3570k @ 4.6Ghz @1.35v Gigabyte Z77x UD3H evga GTX 970 SSC 16Gb Gskill Ripjaws 2133Mhz @ 9-11-10-28 
Hard DriveCoolingOSMonitor
Samsung Evo 850 Thermalright Ultra 120 Extreme Windows 10 Spy Delux Xstar 27" PLS 1440p 
KeyboardPowerCaseMouse
Wireless ergonomic Silverstone 900 watt Silverstone Raven (1st edition) Logisys Wireless trackball 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Why is this correct? Looks to me like it shouldn't work.