I'm still a beginner guys, so I don't know if what I'm doing is right...
In the code below I have a global Dictionary for player 1 and player 2. I then have a Function whereby player 1 chooses if he wishes to play as "x" or "o"... he/she is then assigned the choice, is there a way for me to automatically assign the opposite choice to the other player?
If this is a silly question, I apologize, I don't know
player1 = {"key1" : " "}
player2 = {"key2" : " "}
def start_game():
print('Welcome to Tic Tac Toe')
y = input("Player 1, select your marker (x/o): ")
only_choice = ['x', 'o']
if y in only_choice:
player1['key1'] = y
Related
Does not display anything after data entry
program g
implicit none
real::q,n,s,z,q2,y,free_board,r,b,e,A,h,t
write(*,100)"pls insert discharge Q ="
read(*,*)q
write(*,100)"please insert Manning coefficient n ="
read(*,*)n
write(*,*)"please insert slope of the hydraulic channel ="
read(*,*)s
write(*,*)"please inset Z ="
read(*,*)z
write(*,*)"how much of b/y do you want?"
write(*,*)"if it not important right 2.5"
read(*,*)e
if(e<2.or.e>5)then
stop
end if
y=0
do
b=y*e
A=b+2*y*((1+Z**2)**(0.5))
R=((b+z*y)*y)/(b+(2*y*(1+z**2)**(0.5)))
h=(1/n)*(r**(2/3))*A*(s)**0.5
if( abs(h-q)<0.01) then
exit
end if
y=0.001+y
end do
free_board=0.2*y
h=free_board+y
t=b+2*y*z
write(*,100)"free board="
write(*,*) free_board
write(*,100)"y="
write(*,*)y
write(*,100)"b="
write(*,*)b
write(*,100)"T="
write(*,100)t
100 format(A)
end program g
this not work and not show anything after enter data
For sure the line write(*,100)t will give you a wrong output, since "t" it is a real, not a string. Please change it to write(*,*).
With all inputs equal to 1.0 and by putting e=2.5, I see these output (at screen):
free board = 3.7200041E-02
y = 0.1860002
b = 0.4650005
T = 0.8370009
If you don't see outputs, maybe you are choosing wrong "e" values (less than 2 or more than 5).
So I was able to run part of a program doing below (using tuples)
def reverse_string():
string_in = str(input("Enter a string:"))
length = -int(len(string_in))
y = 0
print("The reverse of your string is:")
while y != length:
print(string_in[y-1], end="")
y = y - 1
reverse_string()
The output is:
Enter a string:I Love Python
The reverse of your string is:
nohtyP evoL I
I am still thinking how for the program to reverse the position of the words instead of per letter.
The desired output will be "Phython Love I"
Is there anyway that I will input a string and then convert it to a tuple similar below:
So If I enter I love Phyton, a certain code will do as variable = ("I" ,"Love", "Python") and put additional codes from there...
Newbie Programmer,
Mac
I'm working on a game and am stuck on a part where a key is supposed to unlock the door of a room. Now, after some searching, I've come across that i can't call a variable that exists in one function, into another function: as i have been trying to by setting i.e.key_picked = True under a conditional in the kitchen function. And then, using a conditional in the room function, with the key_pickedin a Boolean expression.
So, how do i work around this?
def kitchen(already_there=False):
if choice02_key == "pick key" or choice02_key == "0" or choice02_key == "key":
print("---------------------------------------------------------")
print "You picked the key. It probably unlocks some door."
key_picked = True
kitchen(already_there=True)
def room01(already_there=False):
if key_pick == True:
print("---------------------------------------------------------")
print "You unlocked the room using the key."
else:
print "This room is locked."
entrance_hall(already_there=True)
You can pass the variable in a parameter. For example:
Define keyPicked in room01.
Call kitchen(already_there, keyPicked) from room01.
Make the assignment you want.
Then, you will have the value you want in keyPicked.
For example, imagine I have a function that add 10 to a number. This will be better to return the value, but it is just to show you how can you do it.
def add_ten(number):
number = number + 10
def main():
number = 5
print('Number is:', number)
add_ten(number)
print('Number is:', number)
Output:
Number is: 5
Number is: 15
So basically I have to tell the user if the staff working in a phone shop has earned a bonus. If the staff sold 4 or more phones, they get a bonus.
Problem is I keep getting this error.
if list[member_number]>=4:
TypeError: 'int' object is not subscriptable
This is my code-
How_Many_Members= int(input("Enter the number of staff members:"))
list=[]
member=1
while len(list)!= How_Many_Members:
print("how many phones did the member", member,"sold?",end=" ")
Sales=int(input(""))
list.append(Sales)
member=member+1
member_number=0
for list in range(0,How_Many_Members,1):
if list[member_number]>=4:
print("member",member_number,"has earned a bonus")
member_number=member_number+1
else:
print("member",member_number,"has not earned a bonus")
member_number=member_number+1
You have two list objects. One is an array, and the other is an object in a for statement, here:
for list in range(0,How_Many_Members,1):
You are using duplicates, and that's not good and is the thing causing your program to spit the error. It is using that list instead of the array list. And since the list in the for loop is an integer object, the error is thrown. You are basically trying to use subscript on an array but it mistakes it as the integer from the for loop because it is ambiguous. Try the following:
How_Many_Members = int(input("Enter the number of staff members:"))
list = []
member = 1
while len(list) != How_Many_Members:
print("how many phones did the member", member, "sold?", end=" ")
Sales = int(input(""))
list.append(Sales)
member += 1
member_number = 0
for _ in range(0, How_Many_Members, 1):
if list[member_number] >= 4:
print("member", member_number + 1, "has earned a bonus")
member_number += 1
else:
print("member", member_number + 1, "has not earned a bonus")
member_number += 1
Something else, you misspelled member_number in a few places and I fixed that for you. I also shorted some statements and let it print member 1 instead of member 0.
Your problem is here:
for list in range(0,How_Many_Members,1):
if list[member_number]>=4:
print("member",memeber_number,"has earned a bonus")
member_number=member_number+1
else:
print("member",memeber_number,"has not earned a bonus")
member_number=member_number+1
You are saying for list in range(0, How_Many_Members), so list is taking an integer value from 0 to How_Many_Members-1. So it's not a list anymore and you can't do list[member_number].
Keep getting syntax error.
I keep getting........
CODE:
answer = "b"
question = "1) Who made the game Grand Theft Auto 5??\nPlease choose from the following and write a letter: \n◘ A)Viral\n◘ B)Rockstar Games\n◘ C)Madfinger\n◘ D)Gameloft"
print(question)
guess=input().lower()
name=input("Please enter your answer: ")
if guess ==answer:
print("Correct")
score = score + 1
print("Score:")
print(score)
else:
print("Wrong")
You never use name, so why not removing it?
answer = "b"
question = "1) Who made the game Grand Theft Auto 5??\nPlease choose from the following and write a letter: \n◘ A)Viral\n◘ B)Rockstar Games\n◘ C)Madfinger\n◘ D)Gameloft\n"
print(question)
guess=input("Please enter your answer: ").lower()
if guess ==answer:
print("Correct")
score = score + 1
print("Score:")
print(score)
else:
print("Wrong")