263 views
3 votes
Write a program that asks a user to roll a single die twice to get a sum value of 7. If the sum is 11, the user loses. If the sum is neither 7 nor 11, the user neither wins nor loses, meaning that there is no decision. The computations have to be made inside a function named roll_die_twice. The input arguments are the numbers that show up in each die when it is rolled.

User Naved Alam
by
5.5k points

2 Answers

4 votes

Answer:

def roll_die_twice(num1, num2):

if num1 + num2 == 7:

print("You won")

elif num1 + num2 == 11:

print("You lost")

elif (num1 + num2 != 7) or (num1 + num2 != 11):

print("No winner or loser")

n1 = int(input("Roll the dice: "))

n2 = int(input("Roll the dice again: "))

roll_die_twice(n1, n2)

Step-by-step explanation:

Create a function called roll_die_twice that takes two parameter, num1 and num2

Inside function, check the sum of the two numbers. If sum is equal to 7, print "You won". If sum is equal to 11, print "You lost". If sum is neither 7 nor 11, print "No winner or loser".

Get the numbers from the user

Call the function with given numbers

User Joe Mornin
by
5.0k points
3 votes

Answer:

Check the explanation

Step-by-step explanation:

#include <stdio.h>

int dice1;

int dice2;

int sum;

int roll_die_twice(int dice1,int dice2){

if(sum==7){

printf("winner");

}

else if (sum==11){

printf("looser");

}

else if (sum!=7 && sum!=11)

{

printf("nor winner or looser");

}

}

int main()

{

roll_die_twice(2,7);

return 0;

}

The code screenshot and code output can be seen in the attached image below.

Write a program that asks a user to roll a single die twice to get a sum value of-example-1
User Melsi
by
5.6k points