Jump to content

Help with computing homework.py (PYTHON)

Go to solution Solved by Kiwi00000,

It depends on the editor that you are using. Just look at the colours you have.

 

Boolean expressions = when we compare something to either be true or false.

counter<=myNumber   --> Comparing numbers.
(myNumber) % int (counter)==0)  -> comparing the remainder to zero.
 

Both of these expressions evaluate something against something else.

Hi,so if you read the title already then you will know what i need help with. So in computing we are learning python (version 2.7.8) and we were given a homework sheet with two questions on 1) identify the BOOLEAN expressions, 2) Explain what the different colored text is for in python. but we haven't done BOOLEAN expressions before and i have no clue what the colored text in python means. any and all help will be appreciated. 

 

print ('this program works out all the factors of a number.')

myNumber = raw_input ('Enter a number between 1 and 1000')

counter=1

while (counter<=myNumber):
          if (int (myNumber) % int (counter)==0):
                    print (counter, 'is a factor')

           counter=counter+1

Q1..............................
Q2.............................

Edited by AdsStan

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to comment
https://linustechtips.com/topic/217679-help-with-computing-homeworkpy-python/
Share on other sites

Link to post
Share on other sites

boolean = true or false

 

green = strings

blue = functions

black = anything else

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

boolean = true or false

 

green = strings

blue = functions

black = anything else

is that right because on python it shows up is pinky purple, orange, green and black

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

is that right because on python it shows up is pinky purple, orange, green and black

Well the colours depend on what editing program you use. In the forum (as you can see from your post) the colours are different.

 

If you take a screenshot of the program on your computer I will be able to help you more.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

It depends on the editor that you are using. Just look at the colours you have.

 

Boolean expressions = when we compare something to either be true or false.

counter<=myNumber   --> Comparing numbers.
(myNumber) % int (counter)==0)  -> comparing the remainder to zero.
 

Both of these expressions evaluate something against something else.

Link to post
Share on other sites

Well the colours depend on what editing program you use. In the forum (as you can see from your post) the colours are different.

 

If you take a screenshot of the program on your computer I will be able to help you more.

i just use the python gui

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

i just use the python gui

Yeah I have no idea what that is...

People usually use a program to edit their programs, maybe you're talking about the terminal?

 

Can you give a screenshot?

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

It depends on the editor that you are using. Just look at the colours you have.

 

Boolean expressions = when we compare something to either be true or false.

counter<=myNumber   --> Comparing numbers.

(myNumber) % int (counter)==0)  -> comparing the remainder to zero.

 

Both of these expressions evaluate something against something else.

ok so a Boolean expression is when you compare one thing to another?

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

Yeah I have no idea what that is...

People usually use a program to edit their programs, maybe you're talking about the terminal?

 

Can you give a screenshot?

here dude

 

post-88732-0-14541500-1411069732.png

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

here dude

 

Capture.PNG

ok green is string

purple is built in functions

orange is some other type of function idk what it is called (or why its coloured differently)

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to post
Share on other sites

post-88732-0-87923600-1411070053.png

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

Yes.

 

When you see

 

==, >=, <=, !=, etc

 

It all has a value of true of false in the end. (Normally to see if an "IF" statement or a loop will happen.)

 

https://en.wikipedia.org/wiki/Boolean_expression

oh i see now ok so what is the % for?

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

ok green is string

purple is built in functions

orange is some other type of function idk what it is called (or why its coloured differently)

uh will this help?

 

post-88732-0-39168800-1411070326.png

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

It is the remainder of a division.

 

3/2 = 1

If I have 3 pies and two people. Then I have 1 pie left over. I can't give it out to people because I don't have a knife. So, I have 1 left.

oh ok cool i just need to workout the colors. thanks @Kiwi00000

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

right so so far i know for sure that green is string yes

Bapple \ '-' /

Personal Rig - FX 6300 ////// MSI R9 280 ////// ASUS M5A97 R2.0 ////// WD 1TB HDD ////// BitFenix NEOS Case ////// Corsair CX500M //////

Laptop - Toshiba Satellite L850D-12P ////// Tablet - Toshiba Excite ////// Mobile ​- OnePlus One //////

Link to post
Share on other sites

Type in the program below.

Then go to http://en.wikipedia.org/wiki/Python_%28programming_language%29 and see what everything means. eg: built in types might all be the same colour in your program. And flow control (Loops/if statements) might be the same.

 

--------

 

 

def function1():
  return 'a'

a =0

while (a < 10):
  print "a"
  a+=1

for x in range(0, 3):
    print "%d" % (x)
    
a = function1()
print "%c" %(a)

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×