Home > Software design >  How to count number of outputs?
How to count number of outputs?

Time:11-06

I have a simple problem, for which I have to find how many numbers in a specified interval where the digits of one number are all different. I wrote the code to find these numbers but can't count how many outputs? for example, 244 is not acceptable as two digits are similar, 243 is acceptable because all digits are different. I just want to count how many outputs I have.

list = []
for i in range(234,567):
    list.append (i)
for n in list:
    x=[int(a) for a in str(n)]
    if  x[0] != x[1] !=x[2] and x[0]!= x[2]:
        strings = [str(number) for number in x]
        a_string="".join (strings)
        finalrz=int(a_string)
        print (finalrz)

CodePudding user response:

You could create an int variable and after the output is printed 1 to the variable. Make sure the variable isn't in the for loop because it will reset the variable every iteration.

#NEW CODE
count = 0
#END OF NEW CODE
list = []
for i in range(234,567):
    list.append (i)
for n in list:
    x=[int(a) for a in str(n)]
    if  x[0] != x[1] !=x[2] and x[0]!= x[2]:
        strings = [str(number) for number in x]
        a_string="".join (strings)
        finalrz=int(a_string)
        print (finalrz)
        #NEW CODE
        count = count   1
        print(count, "outputs")

CodePudding user response:

output of this code(number 2) is : 234

1 outputs

235

2 outputs

236

3 outputs

237

4 outputs

238 5 outputs 239 6 outputs 240 7 outputs 241 8 outputs 243 9 outputs 245 10 outputs 246 11 outputs 247 12 outputs 248 13 outputs 249 14 outputs 250 15 outputs 251 16 outputs 253 17 outputs 254 18 outputs 256 19 outputs 257 20 outputs 258 21 outputs 259 22 outputs 260 23 outputs 261 24 outputs 263 25 outputs 264 26 outputs 265 27 outputs 267 28 outputs 268 29 outputs 269 30 outputs 270 31 outputs 271 32 outputs 273 33 outputs 274 34 outputs 275 35 outputs 276 36 outputs 278 37 outputs 279 38 outputs 280 39 outputs 281 40 outputs 283 41 outputs 284 42 outputs 285 43 outputs 286 44 outputs 287 45 outputs 289 46 outputs 290 47 outputs 291 48 outputs 293 49 outputs 294 50 outputs 295 51 outputs 296 52 outputs 297 53 outputs 298 54 outputs 301 55 outputs 302 56 outputs 304 57 outputs 305 58 outputs 306 59 outputs 307 60 outputs 308 61 outputs 309 62 outputs 310 63 outputs 312 64 outputs 314 65 outputs 315 66 outputs 316 67 outputs 317 68 outputs 318 69 outputs 319 70 outputs 320 71 outputs 321 72 outputs 324 73 outputs 325 74 outputs 326 75 outputs 327 76 outputs 328 77 outputs 329 78 outputs 340 79 outputs 341 80 outputs 342 81 outputs 345 82 outputs 346 83 outputs 347 84 outputs 348 85 outputs 349 86 outputs 350 87 outputs 351 88 outputs 352 89 outputs 354 90 outputs 356 91 outputs 357 92 outputs 358 93 outputs 359 94 outputs 360 95 outputs 361 96 outputs 362 97 outputs 364 98 outputs 365 99 outputs 367 100 outputs 368 101 outputs 369 102 outputs 370 103 outputs 371 104 outputs 372 105 outputs 374 106 outputs 375 107 outputs 376 108 outputs 378 109 outputs 379 110 outputs 380 111 outputs 381 112 outputs 382 113 outputs 384 114 outputs 385 115 outputs 386 116 outputs 387 117 outputs 389 118 outputs 390 119 outputs 391 120 outputs 392 121 outputs 394 122 outputs 395 123 outputs 396 124 outputs 397 125 outputs 398 126 outputs 401 127 outputs 402 128 outputs 403 129 outputs 405 130 outputs 406 131 outputs 407 132 outputs 408 133 outputs 409 134 outputs 410 135 outputs 412 136 outputs 413 137 outputs 415 138 outputs 416 139 outputs 417 140 outputs 418 141 outputs 419 142 outputs 420 143 outputs 421 144 outputs 423 145 outputs 425 146 outputs 426 147 outputs 427 148 outputs 428 149 outputs 429 150 outputs 430 151 outputs 431 152 outputs 432 153 outputs 435 154 outputs 436 155 outputs 437 156 outputs 438 157 outputs 439 158 outputs 450 159 outputs 451 160 outputs 452 161 outputs 453 162 outputs 456 163 outputs 457 164 outputs 458 165 outputs 459 166 outputs 460 167 outputs 461 168 outputs 462 169 outputs 463 170 outputs 465 171 outputs 467 172 outputs 468 173 outputs 469 174 outputs 470 175 outputs 471 176 outputs 472 177 outputs 473 178 outputs 475 179 outputs 476 180 outputs 478 181 outputs 479 182 outputs 480 183 outputs 481 184 outputs 482 185 outputs 483 186 outputs 485 187 outputs 486 188 outputs 487 189 outputs 489 190 outputs 490 191 outputs 491 192 outputs 492 193 outputs 493 194 outputs 495 195 outputs 496 196 outputs 497 197 outputs 498 198 outputs 501 199 outputs 502 200 outputs 503 201 outputs 504 202 outputs 506 203 outputs 507 204 outputs 508 205 outputs 509 206 outputs 510 207 outputs 512 208 outputs 513 209 outputs 514 210 outputs 516 211 outputs 517 212 outputs 518 213 outputs 519 214 outputs 520 215 outputs 521 216 outputs 523 217 outputs 524 218 outputs 526 219 outputs 527 220 outputs 528 221 outputs 529 222 outputs 530 223 outputs 531 224 outputs 532 225 outputs 534 226 outputs 536 227 outputs 537 228 outputs 538 229 outputs 539 230 outputs 540 231 outputs 541 232 outputs 542 233 outputs 543 234 outputs 546 235 outputs 547 236 outputs 548 237 outputs 549 238 outputs 560 239 outputs 561 240 outputs 562 241 outputs 563 242 outputs

564

243 outputs

CodePudding user response:

output is : 234 235 236 237 238 239 240 241 243 245 246 247 248 249 250 251 253 254 256 257 258 259 260 261 263 264 265 267 268 269 270 271 273 274 275 276 278 279 280 281 283 284 285 286 287 289 290 291 293 294 295 296 297 298 301 302 304 305 306 307 308 309 310 312 314 315 316 317 318 319 320 321 324 325 326 327 328 329 340 341 342 345 346 347 348 349 350 351 352 354 356 357 358 359 360 361 362 364 365 367 368 369 370 371 372 374 375 376 378 379 380 381 382 384 385 386 387 389 390 391 392 394 395 396 397 398 401 402 403 405 406 407 408 409 410 412 413 415 416 417 418 419 420 421 423 425 426 427 428 429 430 431 432 435 436 437 438 439 450 451 452 453 456 457 458 459 460 461 462 463 465 467 468 469 470 471 472 473 475 476 478 479 480 481 482 483 485 486 487 489 490 491 492 493 495 496 497 498 501 502 503 504 506 507 508 509 510 512 513 514 516 517 518 519 520 521 523 524 526 527 528 529 530 531 532 534 536 537 538 539 540 541 542 543 546 547 548 549 560 561 562 563 564

at the result : 564 - 234 1 = 331

final answer is : 331 .

  • Related