Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sp4l2c1 added samples for other languages #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions sprint4/By languages/C#/lesson2code1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// функция bucket вычисляет номер корзины для указанного фрукта
int bucket(String fruit) {
switch (fruit) {
case "яблоко":
return 0;
case "слива":
return 1;
case "груша":
return 2;
default:
throw new ArgumentException("Unknown fruit");
}
}
15 changes: 15 additions & 0 deletions sprint4/By languages/C++/lesson2code1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <string>

// функция bucket вычисляет номер корзины для указанного фрукта
int bucket(std::string fruit) {
if (fruit == "яблоко") {
return 0;
}
if (fruit == "слива") {
return 1;
}
if (fruit == "груша") {
return 2;
}
throw "Unknown fruit";
}
13 changes: 13 additions & 0 deletions sprint4/By languages/JS/lesson2code1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// функция bucket вычисляет номер корзины для указанного фрукта
function bucket(fruit) {
switch (fruit) {
case "яблоко":
return 0;
case "слива":
return 1;
case "груша":
return 2;
default:
throw new IllegalArgumentException("Unknown fruit");
}
}
13 changes: 13 additions & 0 deletions sprint4/By languages/Java/lesson2code1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// функция bucket вычисляет номер корзины для указанного фрукта
public int bucket(String fruit) {
switch (fruit) {
case "яблоко":
return 0;
case "слива":
return 1;
case "груша":
return 2;
default:
throw new IllegalArgumentException("Unknown fruit");
}
}
13 changes: 13 additions & 0 deletions sprint4/By languages/go/lesson2code1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// функция bucket вычисляет номер корзины для указанного фрукта
func bucket(fruit string) int {
switch (fruit) {
case "яблоко":
return 0;
case "слива":
return 1;
case "груша":
return 2;
default:
panic("Unknown fruit");
}
}
24 changes: 24 additions & 0 deletions sprint4/By languages/python/lesson2code1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Функция bucket вычисляет номер корзины для указанного фрукта.
# match-case появился в версии Python 3.10, проверьте, что он поддерживается в вашей среде.
def bucketV1(fruit):
match fruit:
case "яблоко":
return 0
case "слива":
return 1
case "груша":
return 2
case _:
raise "Unknown fruit"


# Функция bucket вычисляет номер корзины для указанного фрукта.
# Реализация для более старых версий Python
def bucketV2(fruit):
if fruit == "яблоко":
return 0
if fruit == "слива":
return 1
if fruit == "груша":
return 2
raise "Unknown fruit"