fizzbuzz

Trying to turn fizzbuzz into a function in python 3

安稳与你 提交于 2021-02-04 20:40:39
问题 I have only just started to learn python as my first language and whilst i worked out the code for fizzbuzz, i cannot for the life of me get it to do the items below. I also want it to print horizontally instead of vertically. Any help would be great (heads spinning). Create a function which does this. For example fizzbuzz(20) would print 1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,17,fizz,19,buzz def fizzbuzz(n): for x in range (101): if x%3==0 and x%5==0: print("fizz buzz")

Trying to turn fizzbuzz into a function in python 3

别等时光非礼了梦想. 提交于 2021-02-04 20:39:14
问题 I have only just started to learn python as my first language and whilst i worked out the code for fizzbuzz, i cannot for the life of me get it to do the items below. I also want it to print horizontally instead of vertically. Any help would be great (heads spinning). Create a function which does this. For example fizzbuzz(20) would print 1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,17,fizz,19,buzz def fizzbuzz(n): for x in range (101): if x%3==0 and x%5==0: print("fizz buzz")

Trying to turn fizzbuzz into a function in python 3

你说的曾经没有我的故事 提交于 2021-02-04 20:38:12
问题 I have only just started to learn python as my first language and whilst i worked out the code for fizzbuzz, i cannot for the life of me get it to do the items below. I also want it to print horizontally instead of vertically. Any help would be great (heads spinning). Create a function which does this. For example fizzbuzz(20) would print 1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,17,fizz,19,buzz def fizzbuzz(n): for x in range (101): if x%3==0 and x%5==0: print("fizz buzz")

C programming. The FizzBuzz program [closed]

前提是你 提交于 2020-04-08 06:53:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I had a quiz and I wrote this code: Print Fizz if it is divisible by 3 and it prints Buzz if it is divisible by 5. It prints FizzBuss if it is divisible by both. Otherwise, it will print the numbers between 1 and 100. But after I arrived home, I wondered if could have writen it with less code. However, I could

Why isn't my “Fizz Buzz” test in R working?

有些话、适合烂在心里 提交于 2020-01-04 19:07:26
问题 I heard this was a common interview question, any ideas what is off here, thank you. for(i in 1:100){ if(i%15==0){ print('fizzbuzz') } else if (i%3==0){ print("fizz") } else if (i%5==0) { print("buzz") } else (print(i)) } } 回答1: I'd place the curly braces in different spots, and you need to correct the operator -- %% instead of % . for(i in 1:100) { if(i%%15==0){ print('fizzbuzz') } else if (i%%3==0){ print("fizz") } else if (i%%5==0) { print("buzz") } else { print(i) } } But the basic idea

FizBuzz program: how to make the output correct?

孤人 提交于 2019-12-31 04:32:11
问题 I got a question about this program, it says: The FizzBuzz Challenge: Display numbers from 1 to x, replacing the word 'fizz' for multiples of 3, 'buzz' for multiples of 5 and 'fizzbuzz' for multiples of both 3 and 5. Th result must be:1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz 16 ... So my problem is at the time to print the output, I dont know what to do. public class Multiplos { public static void main(String args[]) { for (int i = 1; i <= 100; i++) { if (i % 3 == 0) { System

Multiple input values with upper range

試著忘記壹切 提交于 2019-12-25 01:32:28
问题 So I'm in need of a little assistance or at least a point in the right direction! I'm new to Haskell but I'm familiar with C# and PHP. I'm trying to create a FizzBuzz function that allows 3 parameters to be entered. I understand the general concept of FizzBuzz but I'm trying to be able to create a function that allows you to put the first divisor, second divisor and the last parameter as an upper range. The part where I'm struggling to understand is how you assign input values to variables in

How to create the FizzBuzz using loops in JAVA

血红的双手。 提交于 2019-12-24 07:39:28
问题 I'm writing this problem for school and I have some issues with it. I can't get "printFizzBuzz" to actually go up and calculate the wrapper function "FizzBuzz". I am required to use loops and was attempting to use a FOR loop. Beginner programmer here so no, I haven't used loops much at all. Any tips or pointers? ;) The instructions are as follows. public static String FizzBuzz(int number) { if( (number%3==0) && (number%5==0)) { return "FizzBuzz"; } else if( number%3 == 0 ) { return "Fizz"; }

FizzBuzz list comprehension

时光毁灭记忆、已成空白 提交于 2019-12-24 05:56:08
问题 I was messing around with some different fizz buzz scripts as I learn python. I came across this one which works great but I can't decipher how it works. I know how the normal fizz buzz works with a for loop and "if i % 3 == 0 and i % 5 == 0". What has me stumped is how "Fizz" ( not i%3 ) + " Buzz " (not i%5)" works. x = ["Fizz"*(not i%3) + "Buzz"*(not i%5) or i for i in range(1, 100)] 回答1: In python you can replicate a string by using the multiplication operator: print('aaa' * 3) # aaaaaaaaa

Find if a number is divisible by 3 or 5 (FizzBuzz)

此生再无相见时 提交于 2019-12-22 09:48:19
问题 How do I change the output depending on whether or not it is divisible by 3 or 5? If it is divisible by 3, I want to show "rock" and if it's divisible by 5 I want to show "star" (similar to in FizzBuzz). If both, they'll see both. Here's my code: if (var n = Math.floor((Math.random() * 1000) + 1); { var output = ""; if (n % 3 == 0) output += "Rock"; if (n % 5 == 0) output += "star"; prompt(output || n); } Why isn't my code working properly? 回答1: var n = Math.floor((Math.random() * 1000) + 1);