Jul 10, 2017 11:42 AM
(This post was last modified: Jul 10, 2017 02:57 PM by Malentor.)
first of all thank you for the tips on my previous threads, I have took these tips and used them. A user told me to start using try/except , and another user told me to start using ELIF instead making too many if statements.
Here is what I made with these tips:
PHP Code
<?php import os
clients_waiting = []
def options():
try:
while True:
select_option = int(input("""1 = ADD NEW CLIENT TO THE WAITING LIST 2 = SHOW CLIENTS ON THE WAITING LIST 3 = MAKE A CALL TO THE NEXT CLIENT IN THE LIST INSERT YOUR OPTION: """))
if select_option == 1:
add_client()
elif select_option == 2:
show_clients_waiting()
elif select_option == 3:
make_call() except: if select_option != 1 or 2 or 3: print("INVALID") options()
def add_client(): add_client = raw_input("Client name to add: ") clients_waiting.append(add_client) print("Added") os.system('clear') print("Added")
def show_clients_waiting(): os.system('clear') for a , b in enumerate(clients_waiting): a = str(a) print(a + "-> name: " + b)
def make_call(): os.system('clear') who_is_first = min(clients_waiting) print(who_is_first) clients_waiting.remove(who_is_first) print(who_is_first)
options()
I feel happy that only had to use google only once for search how to clear the console after every command , the rest was on my mind.
cya next!!
Jul 10, 2017 01:55 PM
(This post was last modified: Jul 10, 2017 01:55 PM by Crypto Elliot.)
Looks good! There isn't a problem using google or anything. Most people I know are on stack overflow the whole day. Just wondering, what are you learning python for?
You should be using Google. I don't mean that in a bad way, a LOT of programmers use Google still and you can find good improvements while doing so.
Quit centering your code.
(Jul 10, 2017 01:55 PM)Crypto Elliot Wrote: Looks good! There isn't a problem using google or anything. Most people I know are on stack overflow the whole day. Just wondering, what are you learning python for?
My goal for the end of this year is learn as much coding as I can. I already know the basics of PHP and Python, I choose python just because I am little bit familiar with PHP and is almost same sintax.
(Jul 10, 2017 02:05 PM)Malentor Wrote: My goal for the end of this year is learn as much coding as I can. I already know the basics of PHP and Python, I choose python just because I am little bit familiar with PHP and is almost same sintax.
No its really not close to php, for one php doesn't use white space for syntax and php requires lines to end with ;
If are different too
If($var == 'something')
{
//stuff
}
Where as python
If var == 'something':
//stuff
¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Jul 10, 2017 02:35 PM)vorticalbox Wrote: No its really not close to php, for one php doesn't use white space for syntax and php requires lines to end with ;
If are different too
If($var == 'something')
{
//stuff
}
Where as python
If var == 'something':
//stuff Its almost same to me, I'm sorry if you don't think the same. Also in PHP,Python you don't have to state the type of variable, it auto-detect itself, unlike another languages like java or C++ Thats another reason why I think why python is little bit same than PHP and a very easy language to start with.
Jul 10, 2017 02:51 PM
(This post was last modified: Jul 10, 2017 02:54 PM by Malicious Intent.)
In Pytho indentation is very important and this code will not run if you copy and run it. As Charger said .. please dont center the code.. any code... good luck with your learning tho. Python is a good language to know and very useful for quickness. Also .. python might detect the variable type but it doesnt mean you dont need to know or declare the types ...you will understand once you dig deeper into it.
(Jul 10, 2017 02:01 PM)Charger Wrote: Quit centering your code.
i just edited the thread, thanks for heads up
Jul 10, 2017 03:06 PM
(This post was last modified: Jul 10, 2017 03:22 PM by Malicious Intent.)
(Jul 10, 2017 02:57 PM)Malentor Wrote: i just edited the thread, thanks for heads up
Also just noticed .. you dont need to convert the input to int.. its int by default. Another thing is that the exception handling will not work correctly the way it is.. option() is also not needed in exception .. there is few things wrong here but keep trying buddy.
(Jul 10, 2017 03:06 PM)Malicious Intent Wrote: Also just noticed .. you dont need to convert the input to int.. its int by default.
in this line?
select_option = int(input(
I thought i always had to set int for numbers and raw_input for strings
alright thanks :)
(Jul 10, 2017 03:21 PM)Malentor Wrote: in this line?
select_option = int(input(
I thought i always had to set int for numbers and raw_input for strings
alright thanks :)
In python 3+ there is no raw_input .. input can be str or int but its int by default. in python 2.7 you can use raw_input for strings or integers but might have to convert somewhere down the line if you need to make operation on int...
(Jul 10, 2017 03:24 PM)Malicious Intent Wrote: In python 3+ there is no raw_input .. input can be str or int but its int by default. in python 2.7 you can use raw_input for strings or integers but might have to convert somewhere down the line if you need to make operation on int...
good to know, thanks
Code def add_client():
add_client = raw_input("Client name to add: ")
clients_waiting.append(add_client)
print("Added")
os.system('clear')
print("Added")
Also there is no need to print "Added" twice here as it will get cleared by the os.system anyway.
Jul 12, 2017 06:26 PM
(This post was last modified: Jul 12, 2017 06:29 PM by Davian.)
Just a small mistake I thought is worth mentioning,
PHP Code
<?php if select_option != 1 or 2 or 3: print("INVALID") options()
This block will always execute because you're basically checking if 2 or 3 are True, which they are.
Correct way:
PHP Code
<?php if select_option != 1 and select_option != 2 and select_option != 3: print("INVALID") options()
or even better:
PHP Code
<?php if select_option not in (1,2,3): print("INVALID") options()
Keep learning dude you're doing great.
|