Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions exercises/risk-risiko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,58 @@
M 3 vs 3 => blue win
O 2 vs 1 => red win
*/

#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;


int attacker_Dices[3];
int defender_Dices[3];

void compare(){
sort(attacker_Dices, attacker_Dices+ 3, greater<int>());
sort(defender_Dices, defender_Dices + 3, greater<int>());
for(int i=0; i<3; i++){
if(defender_Dices[i]>=attacker_Dices[i])
{
cout<<"N"<<attacker_Dices[i]<<" vs "<<defender_Dices[i]<<
" ==> Blue Win"<<endl;
}
else
{
cout<<"N"<<attacker_Dices[i]<<" vs "<<defender_Dices[i]<<
" ==> Red Win"<<endl;
}
}

}

int main(){
srand(rand()%556745+1);


cout<<"Red Dices:\n";
for(int i=0; i<3; i++){
attacker_Dices[i]= rand() % 5+1;
cout<<attacker_Dices[i]<<endl;


}


cout<<"Blue Dices:\n";
for(int i=0; i<3; i++){
defender_Dices[i]= rand() % 5+1;
cout<<defender_Dices[i]<<endl;

}

compare();





}
9 changes: 9 additions & 0 deletions exercises/somma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def somma1(a,b)->int:
res=a+b
return res
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puoi direttamente effettuare return a + b senza salvarti il valore in una variabile.


a=int(3)
b=int(6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In questo caso non ti serve effettuare il casting a int


risultato_sum=somma1(a,b)
print("SUM = ",risultato_sum)
4 changes: 4 additions & 0 deletions exercises/test_somma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from somma import somma1
def test_somma()->None:
assert somma1(3,5)==8
assert type(somma1(3,5)) is int