What is this? Not a string.. - Overclock.net - An Overclocking Community

Forum Jump: 

What is this? Not a string..

Reply
 
Thread Tools
post #1 of 44 (permalink) Old 10-17-2018, 03:53 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,878
Rep: 19 (Unique: 18)
What is this? Not a string..

What is this? Its not a string. This is part of my python lessons and I'm trying to figure out what exactly it is, and if this can actually be equal. Using python 2 not 3 if that matters. Paying special attention to the part that starts at Cleese. How can Cleese equal King Arthur? And what does the ' mean?



Code:
2 ** 3 == 108 % 100 or 'Cleese' == 'King Arthur'

My understanding is that a string is " and not '

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

Last edited by PhotonFanatic; 10-17-2018 at 04:53 PM.
PhotonFanatic is offline  
Sponsored Links
Advertisement
 
post #2 of 44 (permalink) Old 10-17-2018, 04:45 PM
New to Overclock.net
 
deepor's Avatar
 
Join Date: Feb 2013
Posts: 4,736
Rep: 474 (Unique: 320)
Just try it with Python's interactive shell. Here's what happens for me:

Code:
Python 3.7.0 (default, Sep 15 2018, 19:13:07) 
[GCC 8.2.1 20180831] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello")
hello
>>> print('hello')
hello
>>> "hello" == 'hello'
True
>>>
It seems single quotes work fine and can be used for literal text just like double quotes.
deepor is offline  
post #3 of 44 (permalink) Old 10-17-2018, 05:12 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,878
Rep: 19 (Unique: 18)
So this IS a string then?

Code:
'Here is my string. It is a rather nice string.'

Next question: Can someone write this out mathematically instead of in python speak?

100 ** 0.5

100 to the power of 0.5. That just makes no sense to me. Never considered it, wasn't taught that in school. To me, they gotta be whole numbers. You have to say something like 2 x 2 x 2 x 2 x 2. And then of course you'd have 2 ** 5 in python. That looks much better to me. What would 100 ** 0.5 be?

"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 #4 of 44 (permalink) Old 10-17-2018, 05:15 PM
Robocop is #1 movie ever
 
Dagamus NM's Avatar
 
Join Date: Apr 2014
Location: Albuquerque
Posts: 2,136
Rep: 70 (Unique: 49)
Quote: Originally Posted by PhotonFanatic View Post
So this IS a string then?

Code:
'Here is my string. It is a rather nice string.'

Next question: Can someone write this out mathematically instead of in python speak?

100 ** 0.5

100 to the power of 0.5. That just makes no sense to me. Never considered it, wasn't taught that in school. To me, they gotta be whole numbers. You have to say something like 2 x 2 x 2 x 2 x 2. And then of course you'd have 2 ** 5 in python. That looks much better to me. What would 100 ** 0.5 be?
Wouldn't 100 ** 0.5 be 10? SQRT(100)?

Ol' Dirty Bastard
(29 items)
CPU
6950X
Motherboard
Asus Rampage V edition 10
GPU
Titan X Pascal
GPU
Titan X Pascal
RAM
G.Skill Ripjawz 4 128GB 3200MHz C14 RGB
Hard Drive
Intel 730 series 480GB
Hard Drive
Intel 730 series 480GB
Hard Drive
Intel 6000P 1TB m.2
Hard Drive
WD Black 6TB
Optical Drive
Asus external BD DVD
Power Supply
eVGA 1600W P2
Cooling
EK RVE Edition 10 monoblock
Cooling
EK Titan X Pascal waterblocks with EK back plates
Cooling
Aquacomputer 420mm rad/res/pump combo
Cooling
Aquaero 6 Pro
Cooling
Aquacomputer 420mm rad
Cooling
Aquacomputer 420mm rad
Cooling
Aquacomputer 420mm rad
Cooling
Aquacomputer serial dual D5 pumps with bitspower top and mounts
Case
Caselabs s8
Operating System
Windows 10 Pro
Monitor
Asus pb287q
Monitor
Asus pb287q
Monitor
Asus pb287q
Keyboard
Microsoft Sculpt Wireless Ergonomic
Mouse
Logitech wireless trackball
Audio
Cambridge Audio DacMagic 100+
Audio
Sennheiser HD650
Other
Logitech F710 wireless game pad
▲ hide details ▲
Dagamus NM is offline  
post #5 of 44 (permalink) Old 10-17-2018, 06:10 PM
New to Overclock.net
 
deepor's Avatar
 
Join Date: Feb 2013
Posts: 4,736
Rep: 474 (Unique: 320)
Yeah, 100 ** 0.5 is the same as sqrt(100). Here's how you can explain how that happens:

Let's check out a super simple example to think about what exponentiation is:

10 ** 3
= 1000

You know how that example works, this here is happening behind the scenes:

10 ** 3
= 10 * 10 * 10
= 1000

Playing around with things a bit, you can do this here:

10 ** 3
= 10 ** (2 + 1)
= (10 ** 2) * (10 ** 1)
= 100 * 10
= 1000

Now going back to that 100 ** 0.5 which is confusing, let's think about 100 ** 1 first:

100 ** 1
= 100

Let's split that "1" into two halves:

100 ** 1
= 100 ** (0.5 + 0.5)
= (100 ** 0.5) * (100 ** 0.5)

Do you see what's happening? That's where the answer for 100 ** 0.5 is coming from, and it's "10":

100 ** 0.5
= 10
deepor is offline  
post #6 of 44 (permalink) Old 10-18-2018, 04:44 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,878
Rep: 19 (Unique: 18)
Thanks for the explanation it is much appreciated! Yes I can see what is happening, but I think that I don't like it lol. It seems to me that there are far better and more efficient and even more sensible ways of saying it. Probably why they just don't in normal math speak. The sqrt is perfect imo.

Anyway I'm glad you explained it. Now I'll move on to my next question. In the code below, there is an error in the logic, at least to me.

Code:
# Complete the if and elif statements!
def grade_converter(grade):
    if grade >= 90:
        return "A"
    elif grade >= 80:
        return "B"
    elif grade >= 70:
        return "C"
    elif grade >= 65:
        return "D"
    else:
        return "F"
      
# This should print an "A"      
print grade_converter(92)

# This should print a "C"
print grade_converter(70)

# This should print an "F"
print grade_converter(61)
Near the top, how can you say if the grade is = or > 90, then return an A. But then the next thing you say, is that if the grade is > or = an 80, then you return a B. Because 90-100 are also greater than 80. So wouldn't this confuse python and it wouldn't know whether to give you an A, or a B? If in fact you earned a score that was somewhere in the 80-89 range.

"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 #7 of 44 (permalink) Old 10-18-2018, 04:55 PM
New to Overclock.net
 
xToaDx's Avatar
 
Join Date: Jul 2008
Posts: 3,015
Rep: 276 (Unique: 225)
Quote: Originally Posted by PhotonFanatic View Post
Thanks for the explanation it is much appreciated! Yes I can see what is happening, but I think that I don't like it lol. It seems to me that there are far better and more efficient and even more sensible ways of saying it. Probably why they just don't in normal math speak. The sqrt is perfect imo.

Anyway I'm glad you explained it. Now I'll move on to my next question. In the code below, there is an error in the logic, at least to me.

Code:
# Complete the if and elif statements!
def grade_converter(grade):
    if grade >= 90:
        return "A"
    elif grade >= 80:
        return "B"
    elif grade >= 70:
        return "C"
    elif grade >= 65:
        return "D"
    else:
        return "F"
      
# This should print an "A"      
print grade_converter(92)

# This should print a "C"
print grade_converter(70)

# This should print an "F"
print grade_converter(61)
Near the top, how can you say if the grade is = or > 90, then return an A. But then the next thing you say, is that if the grade is > or = an 80, then you return a B. Because 90-100 are also greater than 80. So wouldn't this confuse python and it wouldn't know whether to give you an A, or a B? If in fact you earned a score that was somewhere in the 80-89 range.
In normal math speak, it is perfectly acceptable to raise something to the 1/2 power. In fact it is very common.

Your code will only get to the > or = 80 portion if the grade is less than 90. It's executing those else-if (elif) statements in order from the top down. Same thing for C, it'll only get to the 3rd statement if the first two haven't been met. Hopefully that makes sense.

xToaDx is offline  
post #8 of 44 (permalink) Old 10-18-2018, 05:48 PM
Robocop is #1 movie ever
 
Dagamus NM's Avatar
 
Join Date: Apr 2014
Location: Albuquerque
Posts: 2,136
Rep: 70 (Unique: 49)
I am trying to decide if I want to take a python class next semester or Adobe Illustrator. I work full time and will be taking an access class that I need for work. I need to take a second class to keep my student loans away.

Sorry to threadjack, was reading and just started typing what I was thinking.

How is your python class?

Ol' Dirty Bastard
(29 items)
CPU
6950X
Motherboard
Asus Rampage V edition 10
GPU
Titan X Pascal
GPU
Titan X Pascal
RAM
G.Skill Ripjawz 4 128GB 3200MHz C14 RGB
Hard Drive
Intel 730 series 480GB
Hard Drive
Intel 730 series 480GB
Hard Drive
Intel 6000P 1TB m.2
Hard Drive
WD Black 6TB
Optical Drive
Asus external BD DVD
Power Supply
eVGA 1600W P2
Cooling
EK RVE Edition 10 monoblock
Cooling
EK Titan X Pascal waterblocks with EK back plates
Cooling
Aquacomputer 420mm rad/res/pump combo
Cooling
Aquaero 6 Pro
Cooling
Aquacomputer 420mm rad
Cooling
Aquacomputer 420mm rad
Cooling
Aquacomputer 420mm rad
Cooling
Aquacomputer serial dual D5 pumps with bitspower top and mounts
Case
Caselabs s8
Operating System
Windows 10 Pro
Monitor
Asus pb287q
Monitor
Asus pb287q
Monitor
Asus pb287q
Keyboard
Microsoft Sculpt Wireless Ergonomic
Mouse
Logitech wireless trackball
Audio
Cambridge Audio DacMagic 100+
Audio
Sennheiser HD650
Other
Logitech F710 wireless game pad
▲ hide details ▲
Dagamus NM is offline  
post #9 of 44 (permalink) Old 10-20-2018, 11:03 PM - Thread Starter
New to Overclock.net
 
PhotonFanatic's Avatar
 
Join Date: Dec 2009
Posts: 1,878
Rep: 19 (Unique: 18)
Quote: Originally Posted by xToaDx View Post

Your code will only get to the > or = 80 portion if the grade is less than 90. It's executing those else-if (elif) statements in order from the top down. Same thing for C, it'll only get to the 3rd statement if the first two haven't been met. Hopefully that makes sense.
I was thinking that maybe since 90+ was already assigned something else, maybe it would just exclude it. But yeah top down makes sense.

Quote: Originally Posted by Dagamus NM View Post
I am trying to decide if I want to take a python class next semester or Adobe Illustrator. I work full time and will be taking an access class that I need for work. I need to take a second class to keep my student loans away.
I'm doing code academy. I'd definitely recommend it as it is interactive. And its free for main portion. If you want some quizzes, and a several projects, then you can pay $20 per month for a few months in order to gain access to that. But there are only so many extras, so you could pay for a few months and then just turn it off when you're done. I am doing code academy in order to get ready for the python class which will start in early january iirc. I want to make sure there is no way I will fall behind in the class. I don't want to have to take it a second time.

I'm hoping that one class will be all it takes, to make me ready to seek work programming in python language. They say you can learn to code in a few months, so we'll see if that is true. Gotta find out if there is more than one class for python.

"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 #10 of 44 (permalink) Old 10-21-2018, 02:16 AM
New to Overclock.net
 
deepor's Avatar
 
Join Date: Feb 2013
Posts: 4,736
Rep: 474 (Unique: 320)
That "elif" has the same meaning as doing this nested structure of "if"s here:

Code:
if grade >= 90:
    return "A"
else:
    if grade >= 80:
        return "B"
    else:
        if grade >= 70:
            return "C"
        else:
            if grade >= 65:
                return "D"
            else:
                return "F"
That "elif" is there so that you can write this in a shorter way without this ridiculous nesting, but it's still the same meaning.

Quote: Originally Posted by PhotonFanatic View Post
[...] Near the top, how can you say if the grade is = or > 90, then return an A. But then the next thing you say, is that if the grade is > or = an 80, then you return a B. Because 90-100 are also greater than 80. So wouldn't this confuse python and it wouldn't know whether to give you an A, or a B? If in fact you earned a score that was somewhere in the 80-89 range.
Python is not getting confused because it's not doing all of those "if + elif + elif + ..." questions at the same time. It's working through that nested structure of "else" paths and working on just one "if" question at a time.
deepor 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