fn main() {let number = 13;// TODO ^ Try different values for `number`println!("Tell me about {}", number);match number {// Match a single value1 => println!("One!"),// Match several values2 | 3 | 5 | 7 | 11 => println!("This is a prime"),// Match an inclusive range13...19 => println!("A teen"),// Handle the rest of cases_ => println!("Ain't special"),}let boolean = true;// Match is an expression toolet binary = match boolean {// The arms of a match must cover all the possible valuesfalse => 0,true => 1,// TODO ^ Try commenting out one of these arms};println!("{} -> {}", boolean, binary);
}
Answer
Thanks for the hint, Andrea Corbellini.
i found that solution, there is pampy
from pampy import match, _def func(x):return match(x,1, "One!",# 2 | 3 | 5 | 7 | 11, "This is a prime", # not work# 2 or 3 or 5 or 7 or 11, "This is a prime", # not work2, "This is a prime",_, "Ain't special")if __name__ == '__main__':print("1: {}".format(func(1)))print("2: {}".format(func(2)))print("3: {}".format(func(3)))print("5: {}".format(func(5)))print("7: {}".format(func(7)))print("nothing: {}".format(func("nothing")))
--
EDIT: Now (2020/06), there is official draft for match PEP 622
Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 6…
This question already has answers here:How to write the Fibonacci Sequence?(67 answers)Closed 6 years ago.n1 = 1
n2 = 1
n3 = n1 + n2
for i in range(10):n1 + n2print(n3)n1 = n2n2 = n3According to what …
Hi I am currently writing a snake game code and I am nearly finished however I am having difficulty writing a code which will cause the game to end if the head of the snake collides with its body, I th…
when I try to call the changeProfile function, I keep getting the error "getAuthCode is not defined" even though it is clearly defined. Why do I keep getting this error? What am I doing wron…
Im supposed to write a function max_and_min that accepts a tuple containing integer elements as an argument and returns the largest and smallest integer within the tuple. The return value should be a t…
Problem SummaryGiven 2 excel files, each with 200 columns approx, and have a common index column - ie each row in both files would have a name property say, what would be the best to generate an output…
Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 4…
For my homework assignment, I am using the for loop and the range function. I have to create a loop that printsHello 0
Hello 1
Hello 3
Hello 6
Hello 10The question says that the number corresponds to t…
product_template.xmlthe view to add the customizing field to the product module<?xml version="1.0" encoding="utf-8"?><odoo><data><record id="product_temp…