Skip to content

Error counting in one-liner: #128431

@WolfMS

Description

@WolfMS

Bug report

Bug description:

translate with translate google
I did preliminary tests for a project because I wanted to write the functions in one-liner. When a button is pressed, counting up/down should be done up to a limit value. In the "normal form" everything works correctly, even the down counter works perfectly as a one-liner. But the upward counter seems to multiply by 2 in the following steps after reaching the upper threshold!

x = 10
z = 10
y = 5
w = 5
p = 5


for n in range(12):
    if x > 0:
        x -= 1
    print('x = ', x)

for n in range(12):    
    if w < 10:
        w += 1
    print('w = ', w)
    
for n in range(12):
    z -= 1 if z > 0 else z
    print('z = ', z)
    
for n in range(12):
    
    if y == 5:
        print('y = ', y ,', ', end='')
    y += 1 if y < 10 else y
    print(y, end=', ')
print()
for n in range(12):
    if p == 5:
        print('p = ', p , ', ', end='')
    p += 1 if 10 > p else p
    print(p, end=', ')
[code]

y =  5 , 6, 7, 8, 9, 10, 20, 40, 80, 160, 320, 640, 1280, 
p =  5 , 6, 7, 8, 9, 10, 20, 40, 80, 160, 320, 640, 1280, 

[code]
System: Kernel: 5.4.0-186-generic x86_64 bits: 64 compiler: gcc v: 9.4.0
Desktop: Cinnamon 5.2.7 wm: muffin dm: LightDM Distro: Linux Mint 20.3 Una
base: Ubuntu 20.04 focal
Machine: Type: Desktop Mobo: Gigabyte model: X58A-UD3R serial: BIOS: Award v: FA
date: 04/20/2010
CPU: Topology: Quad Core model: Intel Core i7 950 bits: 64 type: MT MCP arch: Nehalem rev: 5
L2 cache: 8192 KiB
flags: lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx bogomips: 32383
Speed: 2024 MHz min/max: 1596/1995 MHz Core speeds (MHz): 1: 2024 2: 2019 3: 2024
4: 2016 5: 2024 6: 1965 7: 2022 8: 1951
Graphics: Device-1: AMD Cypress PRO [Radeon HD 5850] vendor: Hightech Information System
driver: radeon v: kernel bus ID: 03:00.0 chip ID: 1002:6899
Display: x11 server: X.Org 1.20.13 driver: ati,radeon unloaded: fbdev,modesetting,vesa
resolution: 1920x1080~60Hz
OpenGL: renderer: AMD CYPRESS (DRM 2.50.0 / 5.4.0-186-generic LLVM 12.0.0)
v: 4.3 Mesa 21.2.6 compat-v: 3.1 direct render: Yes
[code]

Python 3.12.5 (main, Aug 21 2024, 19:48:42) [GCC 9.4.0]

[code]

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions