#idk what i did wrong

1 messages · Page 1 of 1 (latest)

upper solstice
karmic raftBOT
#

<@&987246399047479336> please have a look, thanks.

upper solstice
#

i get no output

#

please help thank you

thorny python
#

You're comparing numbers to characters.

#

char P = 'p';

#

Even though you declared user1 and user2 as int's, you can still use == to compare primitive int and char.

#

Ideally you want something easier to understand.

#

String paper = "p";

#

String player1Move = scanner.nextLine()

upper solstice
#

idk if im doing it right

#

sorry im kinda confused

thorny python
#
if( player1Move.startsWith(paper)  && player2Move.startsWith(rock){
   player1wins
}
upper solstice
#

the assignment also told me to say why each user won

thorny python
#

sure, six cases like you have

upper solstice
#

prof havent taught me that one

#

idk if he will allow us to use that statement

thorny python
#

I'm renaming your variables to explain what they are.

#

user1 is player1Move

#

P is paper.

upper solstice
#

oh

thorny python
#

They can all be strings

upper solstice
#

so what do i need to fix here

thorny python
#

Well you need to declare the three strings which will match the player input

upper solstice
#

so i use scnr.nextLine()?

thorny python
#

String paper = "p", rock = "r", scissor = "s";

#

Yes.

upper solstice
#

what about this statement

thorny python
#

and you might as well push everything to lowercase as well

#

scnr.nextLine().toLowerCase()

#

Is the input being entered one at time?

#

with a carriage return?

upper solstice
#

im not sure

thorny python
#

or are you reading from a file

upper solstice
#

this is what i have so far

#

this is the instruction

thorny python
#

hmm. do your submissions get automatically graded?

upper solstice
#

no

#

he graded himself

thorny python
#

So Scanner.next will pull the next string upto some white space out. So if the input is
p r s p p r p s

#

then that is four rounds of the game.

#

You really don't need it as character but whatever. It's his rules.

upper solstice
#

yeah im kinda confused lol

thorny python
#

You can still declare the constant characters you'll check against as char
char paper = 'p', rock = 'r', scissor = 's';

#

char user1 = scnr.next().toLowerCase().charAt(0);

upper solstice
#

i think i got it

thorny python
#

Then in your if statements....

if(user1 == paper && user2 == rock)
upper solstice
#

is it right

thorny python
#

Yes, mostly. We tend to use a constant variable instead of literals though.

upper solstice
#

wdym by that

#

?

#

sorry im kinda new

thorny python
#

instead of
user1 == 'p'

#

Use your defined constant
user1 == paper

upper solstice
#

oh

#

i see

thorny python
#

where you previously defined it as
char paper = 'p';

upper solstice
#

do i leave it like that or change to constant?

thorny python
#

final char paper = 'p';
will do

upper solstice
#

so i put final char under char?

#

like final char rock = 'r';?

thorny python
#

yes

#

final means it can't be accidentally changed

upper solstice
#

do i need to change if statement?

thorny python
#

no

#

well yes, remove the literals, 'p', 'r', 's' and replace with yoru constant variable names

upper solstice
#

i got errors

thorny python
#

ahh, get rid of the first set of paper, rock, scissor declarations

upper solstice
#

more errors lol

#

oh

#

i forgot

#

to delete ''

thorny python
#

your ifs should use the variable.
if(user == paper && ....

#

not user == 'p'

upper solstice
#

i think i got it done

thorny python
#

Ur a wizard, Harry.

upper solstice
#

lol

#

thank you so so much for yourhelp

#

and ur patience

#

i rlly aprreacited your help

thorny python
#

np.

upper solstice
#

i hope you have a really good day

thorny python
#

sure, you too.